sample output that I want:
chocolate bar $1.00
skittles $1.20
marshmellows $5.00
candy-cane $0.90
the output I got:
░"@ $1.00
░"@ $1.20
░"@ $5.00
░"@ $0.90
the code I made:
#include <stdio.h>
void ShowMenu();
int main()
{
int i, j;
float price[4][1]= {1,1.2,5,0.9};
char snack[4][20];
ShowMenu(price, i, j, snack);
return 0;
}
void ShowMenu(float price[4][1], int i, int j, char snack[4][20])
{
for (i=0;i<4;i )
for (j=0;j<1;j )
{
if(i==0)
snack[0][20]=="chocolate bar" ;
else if(i==1)
snack[1][20]=="skittles" ;
else if(i==2)
snack[2][20]=="marshmellows" ;
else if(i==3)
snack[3][20]=="candy-cane" ;
printf("%s RM%.2f\n", snack, price[i][j]);
}
}
CodePudding user response:
- Your function prototype has to be *exactly the same as your definition!!!
- It is hard what is the purpose of many variables and parameters. I have stripped down everything not needed
void ShowMenu(float price[], char *snack[], int nitems);
int main(void)
{
float price[4] = {1,1.2,5,0.9};
char *snack[20] = {"chocolate bar", "skittles", "marshmellows", "candy-cane"};
ShowMenu(price, snack, 4);
return 0;
}
void ShowMenu(float price[], char *snack[], int nitems)
{
for (int i = 0; i < nitems; i )
{
printf("%s\tRM%.2f\n", snack[i], price[i]);
}
}