hi, simple C problem..

i want to write a program that will repetitively read and calculate the total sale for a purchase from a fast food restaurant.
this is the code i ve written until i got stuck:

#include<stdio.h>
main()
{
int menu, quan; // variable declaration
double total, GrandTotal;
char anymore;

printf("\t\t^^^^^^^^^^Welcome to E&E food corner^^^^^^^^^^\n");

printf("\t~~~Menu~~~\n");
printf("1. Value meal 1: RM 8.90 \n");
printf("2. Value meal 2: RM 9.40 \n");
printf("3. Value meal 3: RM 10.50 \n");
printf("4. Side order 1: RM 2.00 \n");
printf("5. Side order 2: RM 3.60 \n");
printf("6. Drink 1: RM 3.50 \n");
printf("7. Drink 2: RM 2.40 \n");


do{

do{
printf("\n\nPlease enter selection menu from 1 to 7:");
scanf("%d", &menu);
if(menu<1||menu>7) //if menu is invalid prompt user to re-enter menu number
printf("Invalid menu number please re-enter\n");
}while(menu<1||menu>7); // loop until user enters a valid menu number

printf("Quantity:");
scanf("%d", &quan);



switch(menu)
{
case 1:printf("%d x Value meal 1", quan);
total=quan*8.90;
printf("\nTotal=RM%.2f\n", total);
break;

case 2:printf("%d x Value meal 2", quan);
total=quan*9.40;
printf("\nTotal=RM%.2f\n", total);
break;

case 3:printf("%d x Value meal 3", quan);
total=quan*10.50;
printf("\nTotal=RM%.2f\n", total);
break;

case 4:printf("%d x Side order 1 ", quan);
total=quan*2.00;
printf("\nTotal=RM%.2f\n", total);
break;

case 5:printf("%d x Side order 2 ", quan);
total=quan*3.60;
printf("\nTotal=RM%.2f\n", total);
break;

case 6:printf("%d x Drink 1 ", quan);
total=quan*3.50;
printf("\nTotal=RM%.2f\n", total);
break;

case 7:printf("%d x Drink 2 ", quan);
total=quan*2.40;
printf("\nTotal=RM%.2f\n", total);
break;
}



printf("Any more orders?(Y/N)\n");
scanf("%s", &anymore);

}while(anymore=='y'||anymore=='Y'); // loop if user still wants to enter order

return 0;
}






if i have more than one order how do i compute the grand total?
tnx
You may want to consider storing orders in a float vector. In case you don't know much about vectors they are more or less a dynamic array. You can change their length and elements as much as you want. To access vectors all you need is the vector.h library included in your program. For more information on vectors follow this link: http://www.cplusplus.com/reference/stl/vector/
Last edited on
This is C. There's no such thing as the STL.

Doing that is easy. Just keep a separate variable and add total to it every time through the loop.
as helios says:
1
2
3
4
5
6
7
double item,total;
while(item)//ctrl+z to quit
   {cout<<"What u want";
   cin>>item;//value of hotdog or whatever
   total+=item;
   }
cout<<"Total owed "<<total<<endl;  
Topic archived. No new replies allowed.