So I am making a basic hotel/restaurant billing system and I am printing a menu and then taking inputs as choices while using a switch statement and the problem is that I am able to add one dish and select how many quantities of that dish you want and add tax and calculate total bill but I am unable to get a total bill for multiple dishes with multiple quantities. But I am able to get a total bill of multiple dishes having the same price and different quantities.
#include<stdio.h>
void main()
{
float food=0; // Total Food bill
float p; // Quantity of food
int ch; // Choice
float vat,gst; // TAX
float total; // Total bill
int w; // Loop variable
printf("\n ***Menu***\n Please choose items which you want to order from the list given below \n ---Tiffins--- \n 1. Plain Dosa = 50/- \n 2. Masala Dosa = 70/- \n 3. Onion Dosa = 80/- \n 4. Idli = 50/- \n 5. Uttapam = 90/- \n 6. Vada = 60/- \n 7. Upma = 65 /- \n 8. Pongal = 70/- \n 9. Puri = 70/- \n ");
// Main Menu
printf("\n Please enter your order: \n");
scanf("%d",&ch); // Choice input
do{ // Loop
switch(ch)
{
case 1:
printf("\n How many plates do you want to order: \n");
scanf("%f",&p);
food = food+50*p;
printf("\nYour total as of right now: %.2f\n",food);
break;
case 2:
printf("\n How many plates do you want to order: \n");
scanf("%f",&p);
food = food+70*p;
printf("\nYour total as of right now: %.2f\n",food);
break;
case 3:
printf("\n How many plates do you want to order: \n");
scanf("%f",&p);
food = food+80*p;
printf("\nYour total as of right now: %.2f\n",food);
break;
case 4:
printf("\n How many plates do you want to order: \n");
scanf("%f",&p);
food = food+50*p;
printf("\nYour total as of right now: %.2f\n",food);
break;
case 5:
printf("\n How many plates do you want to order: \n");
scanf("%f",&p);
food = food+90*p;
printf("\nYour total as of right now: %.2f\n",food);
break;
case 6:
printf("\n How many plates do you want to order: \n");
scanf("%f",&p);
food = food+60*p;
printf("\nYour total as of right now: %.2f\n",food);
break;
case 7:
printf("\n How many plates do you want to order: \n");
scanf("%f",&p);
food = food+65*p;
printf("\nYour total as of right now: %.2f\n",food);
break;
case 8:
printf("\n How many plates do you want to order: \n");
scanf("%f",&p);
food = food+70*p;
printf("\nYour total as of right now: %.2f\n",food);
break;
case 9:
printf("\n How many plates do you want to order: \n");
scanf("%f",&p);
food = food+70*p;
printf("\nYour total as of right now: %.2f\n",food);
break;
default:
printf("\nInvalid choice\n");
}
printf("\nPress 0 to go to billing\n");
scanf("%d",&w);
} while(w>0);
vat = (7*food)/100;
gst = (5*food)/100;
total = food+vat+gst;
printf("\n ---TOTAL BILL--- \n Food Total = %.2f \n Vat(7%%) = %.2f \n GST(5%%) = %.2f \n Total amount = %.2f \n",food,vat,gst,total);
getch();
}
So yes it is a stupid basic beginner question but any help will be greatly appreciated. And yes I am Indian and yes those are Indian dishes.
Thank you!
Edit: Ok thank you its is fixed now all I had to do was move my choice input inside the loop. Thank you all for your help!