I developed a program that is supposed to pass the following members of the array of double purchase from the following function:
float beverages ()
{
char response;
double purchase [8]= {3.50, 3.80, 3.90, 4.20, 4.00, 4.30, 3.00, 3.10};
printf("\nEnter your order: ");
scanf("%c", response);
if (response == 'l')
{
purchase [0];
printf("You have chosen a Regular Long Black coffee\n");
printf("that will be %.2f dollars", purchase [0]);
}
else if (response == 'L')
{
purchase [1];
printf("You have chosen a Large Long Black coffee\n");
printf("that will be %.2f dollars", purchase [1]);
}
else if (response == 'f')
{
purchase [2];
printf("You have chosen a Regular Flat White coffee\n");
printf("that will be %.2f dollars", purchase [2]);
}
else if (response == 'F')
{
purchase [3];
printf ("You have chosen a Large Flat White coffee\n");
printf("that will be %.2f dollars", purchase [3]);
}
else if (response == 'c')
{
purchase [4];
printf("You have chosen a Regular Cappuccino\n");
printf("that will be %.2f dollars", purchase [4]);
}
else if (response == 'C')
{
purchase [5];
printf("You have chosen a Large Cappuccino\n");
printf("that will be %.2f dollars", purchase [5]);
}
else if (response == 't')
{
purchase [6];
printf("You have chosen a Regular Tea\n");
printf("that will be %.2f dollars", purchase [6]);
}
else if (response == 'T')
{
purchase [7];
printf("You have chosen a Large Tea\n");
printf("that will be %.2f dollars", purchase [7]);
}
return purchase[];
}
and I have it in the int main like:
int main()
{
...
printf("MENU!");
decision (choice);
purchase [] = beverages();
...
return 0;
}
with the following code purchase [] = beverages(); there seems to be a problem where the compiler is saying that purchase is undeclared and there is and unexpected expression before the ] token (by the way the errors are only within the int main). It seems that maybe I have not passed the array from the function properly or something? I've tried adding the value 8 e.g purchase[8] = beverages(); but then the compiler says that purchase is not a pointer or an array. How do I debug this? Am I simply not using right syntax or am I not passing the array correctly?
As 'beverages()' function is want to return
double array
then you need to modify likeIn main function you need to modify like
Variable
purchase
defined inbeverages()
is local to that function you can not access it inmain()