The code snippet below is part of the restaurant menu program you previously used in the lab. Add a choice for a drink. Add the necessary code to allow the program to calculate the total price of order for the user. Assume the following price list: Hamburger $5 Hotdog $4 Fries $3 Drink $2 The program should allow the user to keep entering order until choosing to exit. At the end the program prints an order summary like this: You ordered 2 hamburger(s), 1 hotdog(s), 3 fries, 0 drink(s). Price: $23 HST: $2.99 Total: $25.99
The code snippet below is part of the restaurant menu program you previously used in the lab. Add a choice for a drink. Add the necessary code to allow the program to calculate the total price of order for the user. Assume the following price list: Hamburger $5 Hotdog $4 Fries $3 Drink $2 The program should allow the user to keep entering order until choosing to exit. At the end the program prints an order summary like this: You ordered 2 hamburger(s), 1 hotdog(s), 3 fries, 0 drink(s). Price: $23 HST: $2.99 Total: $25.99


Code in C::
#include<stdio.h>
int main(){
int choice;
int hamburger=0,hotdog=0,fries=0,drink=0,exit=0;
do {
printf("What do you want to eat today?\n");
printf("1. Hamburger\n");
printf("2. Hotdog\n");
printf("3. Fries\n");
printf("4. Drinks\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice){
case 1:
printf("You ordered a hamburger\n");
hamburger++;
break;
case 2:
printf("You ordered a hotdog\n");
hotdog++;
break;
case 3:
printf("You ordered fries\n");
fries++;
break;
case 4:
printf("You ordered drinks\n");
drink++;
break;
case 5:
printf("Order finished, thank you!\n");
break;
default:
printf("Wrong choice! try again: ");
break;
}
} while (choice != 5);
int total=hamburger*5+hotdog*4+fries*3+drink*2;
float tax=0.13*total;
float grandTotal=total+tax;
printf("You ordered %d hamburger(s), %d hotdog(s), %d fries, %d drink(s). Price: $%d HST: $%.2f Total: $%.2f",hamburger,hotdog,fries,drink,total,tax,grandTotal);
return 0;
}
Step by step
Solved in 2 steps









