1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
void main() // This should be int main()
{
char ord[50];
int a,b,c,d,e,f,g,h,l;
int cash; int total; int change;
a=25; b=20; c=25; d=15; e=15;f=20;g=15; h=15;
// Clear screen, draw menu.
// etc... code removed for brevity
// Read in the number of items the user wants to order
gets(order); // Read in as a STRING, not an INTEGER
// Assume you meant '0' and not 'o', as the code would not compile with 'o'.
// Since order is of type char[], order is a pointer. This makes 'l' count from
// zero to the value of the pointer.
for(l=o;l<order;l++); // <- Semicolon here ends the for loop (so body does nothing).
// Access the l'th byte of the order array. Since 'l' counted from 0 to the address
// of the order array, l is huge, and this will access well beyond the array bound
// and most certainly crash.
switch( order[l] )
{
// Cases omitted for brevity.
}
// Set total equal to twice the value of 'l', which is again the address of 'order'.
total=l+l;
// Output total cost and ask for payment amount.
printf("\ntotal=%d",total);
printf("\nCash:");
scanf("%d",&l); // Read the payment amount into 'l'
// The change is equal to the amount of the payment minus the total cost.
// The amount of the payment was read into 'l', but here we use 'cash' as
// the payment amount. Also, per above comments, total is not the total
// cost, it is 2 * address of 'order'.
change=cash-total;
// Output the change amount, etc.
printf("\nChange=%d",change);
printf("\n\n%s",PHRASE);
// Pause terminal so window isn't closed immediately
getch();
}
|