Reputation: 25
Im supposed to write a code for a grocery store inventory that does a calculation in a separate function. Ive ran the code without the function and everything runs fine but as soon as I add the function I run into trouble. I keep getting the error telling me:
c:55:6: error: argument ‘b’ doesn’t match prototype c:3:6: error: prototype declaration
I've tried playing around with the values I'm passing through the functions but it doesn't seem to be working. I'm fairly new with arrays so I could be missing something obvious. Any help would be appreciated!
#include <stdio.h>
void value_calc(int, float);
int main(){
int barcode[100], quantity[100], i;
double price[100], value[100], value1;
printf("Grocery Store Inventory\n");
printf("=======================\n");
for(i=0;i<100;i++){
printf("Barcode : ");
scanf("%d", &barcode[i]);
if (barcode[i]==0){
break;
}
printf("Price : ");
scanf("%lf", &price[i]);
printf("Quantity : ");
scanf("%d", &quantity[i]);
value_calc(quantity[i],price[i]);
}
printf("\n Goods in Stock\n");
printf(" ==============\n\n");
printf("Barcode Price Quantity Value\n");
printf("-------------------------------------\n");
for(i=0;i<100 && barcode[i] !=0;i++){
printf("%d %.2lf %8d %.2lf\n", barcode[i], price[i], quantity[i]);
}
return 0;
}
void value_calc(a,b){
double value1;
value1 = a*b;
}
Upvotes: 0
Views: 6340
Reputation: 22447
The declaration
void value_calc(int, float);
does not match the function itself:
void value_calc(a,b)
...
because by default all function arguments are int
. Use the same declaration in your function as in the declaration itself:
void value_calc (int a, float b)
...
Note: I also get a warning on this line, and you should look into it:
<stdin>:46:50: warning: more '%' conversions than data arguments [-Wformat]
printf("%d %.2lf %8d %.2lf\n", barcode[i], price[i], quantity[i]);
Upvotes: 2
Reputation: 133557
The problem is that your definition of value_calc
is omitting argument types:
void value_calc(int, float);
void value_calc(a,b) {
..
}
C allows you to omit argument types but they become int
by default (enable being warned about it with -Wimplicit-int
on GCC and Clang). Now you have a declaration with int, float
and a definition with int, int
, which doesn't match. Try with:
void value_calc(int a, float b) {
..
}
Upvotes: 3