Reputation: 1
So i have an assignment for the university where the user types the prices of some products from a set number of categories he provides and I must find the maximum amount of money he can spend. I also need to use a function for the calculations. I typed the code below and it showed me 2 warnings:
line 21 [Warning] passing argument 3 of 'shop' makes pointer from integer without a cast,
line 21 [Warning] passing argument 4 of 'shop' makes pointer from integer without a cast
and 2 notes:
line 4 [Note] expected 'int *' but argument is of type 'int',
line 4 [Note] expected 'int (*)[10]' but argument is of type 'int'
The code is this one, it is worth mentioning that we were asked to use a header file to combine the main programm with the function instead of writing all in one page:
#include <stdio.h>
#include "shoprec.h"
int shop(int m, int n, int K[n], int C[n][10]);
int main(){
int m, n, i, j, R;
printf("please type the maximum amount of money you want to spend \n");
scanf("%d", &m);
printf("please type how many kinds of products you want to buy (like pc, printers. scanners etc.) \n");
scanf("%d", &n);
int K[n],C[n][10];
for (i=1; i<=n; i++){
printf("please type the amount of available products for category number %d \n", i);
scanf("%d", &K[i]);
for (j=1; j<=K[i]; j++){
printf("please type the cost of product number %d from category number %d \n", j, i);
scanf("%d", &C[i][j]);
}
}
R= shop(m, n, K[n], C[n][10]);
printf ("Maximum amount spent is : %d \n",R)
}
The header file is this one:
int shop(int m, int n, int K[n], int C[n][10]);
And the function code is:
int shop(int m, int n, int K[n], int C[n][10]){
int P,i,j,R;
P=m;
R=0;
for (i=1;i<=n;i++){
for (j=1;j<=K[i];j++){
P=P-C[i][j];
}
if (P>R) R=P;
}
return R;
}
Upvotes: 0
Views: 690
Reputation: 2420
Change R= shop(m, n, K[n], C[n][10]);
to R= shop(m, n, K, C);
When you put the K[n]
you are passing an int
, not an int array
as specified by the function signature.
Upvotes: 1