Question

The code snippet below is part of the restaurant menu program you previously used in the...

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

do { printf("What do you want to eat today?\n"); printf("1. Hamburger\n"); printf("2. Hotdog\n"); printf("3. Fries\n"); printf("4. Exit\n"); printf("Enter your choice: "); scanf("%d", &choice); switch(choice){ case 1: printf("You ordered a hamburger\n"); break; case 2: printf("You ordered a hotdog\n"); break; case 3: printf("You ordered fries\n"); break; case 4: printf("Order finished, thank you!\n"); break; default: printf("Wrong choice! try again: "); } } while (choice != 4);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Explanation::

  • Code in C is given below
  • I have used 13 % as tax
  • OUTPUT is given at the end of the code


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;
}

OUTPUT::

What do you want to eat today?
1. Hamburger
2. Hotdog
3. Fries
4. Drinks
5. Exit
Enter your choice: 1
You ordered a hamburger
What do you want to eat today?
1. Hamburger
2. Hotdog
3. Fries
4. Drinks
5. Exit
Enter your choice: 1
You ordered a hamburger
What do you want to eat today?
1. Hamburger
2. Hotdog
3. Fries
4. Drinks
5. Exit
Enter your choice: 2
You ordered a hotdog
What do you want to eat today?
1. Hamburger
2. Hotdog
3. Fries
4. Drinks
5. Exit
Enter your choice: 3
You ordered fries
What do you want to eat today?
1. Hamburger
2. Hotdog
3. Fries
4. Drinks
5. Exit
Enter your choice: 3
You ordered fries
What do you want to eat today?
1. Hamburger
2. Hotdog
3. Fries
4. Drinks
5. Exit
Enter your choice: 3
You ordered fries
What do you want to eat today?
1. Hamburger
2. Hotdog
3. Fries
4. Drinks
5. Exit
Enter your choice: 5
Order finished, thank you!
You ordered 2 hamburger(s), 1 hotdog(s), 3 fries, 0 drink(s). Price: $23 HST: $2.99 Total: $25.99
Process returned 0 (0x0) execution time : 22.982 s
Press any key to continue.


Please provide the feedback!!

Thank You!!

Add a comment
Know the answer?
Add Answer to:
The code snippet below is part of the restaurant menu program you previously used in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C++ Mr. Manager wants you to process orders for the Fast Greasy Food Shop. His...

    Using C++ Mr. Manager wants you to process orders for the Fast Greasy Food Shop. His customers have a few choices in what they order. The can order a hamburger for 1.00. It they want cheese it is an addition .50 and if they want bacon the additional amount is .75. They can also order a small or large drink for 1.10 and 1.60 respectively and small or large French fries for 1.20 or 1.75 respectively.    The user can only...

  • C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include ...

    C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include <stdio.h> int main() { int fries; // A flag denoting whether they want fries or not. char bacon; // A character for storing their bacon preference. double cost = 0.0; // The total cost of their meal, initialized to start at 0.0 int choice; // A variable new to version 2, choice is an int that will store the // user's menu choice. It will also serve as our loop control...

  • create case 4 do Method 1:copy item by item and skip the item you want to...

    create case 4 do Method 1:copy item by item and skip the item you want to delete after you are done, delete the old file and rename the new one to the old name. #include int main(void) { int counter; int choice; FILE *fp; char item[100]; while(1) { printf("Welcome to my shopping list\n\n"); printf("Main Menu:\n"); printf("1. Add to list\n"); printf("2. Print List\n"); printf("3. Delete List\n"); printf("4. Remove an item from the List\n"); printf("5. Exit\n\n"); scanf("%i", &choice); switch(choice) { case 1:...

  • PLEASE ADD PRICE CHECK IN MY CODE BELOW: ADD THIS: Price check Prompt the user to...

    PLEASE ADD PRICE CHECK IN MY CODE BELOW: ADD THIS: Price check Prompt the user to input the SKU number for the item they are looking for. Search through the inventory and display the cost of the item. Note that if the item does not exist in the inventory, the program displays an informative message. MY CODE: #include <stdio.h> #include <stdlib.h> // define maximum number of items const MAX_ITEMS = 10; //struct to use as asked in problem struct Item{...

  • C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the class program with methods and variables 2. bill.cpp = contains the functions from class file 3. main.cpp = contains the main program. Please split this program into three files and make the program run. I have posted the code here. #include<iostream>...

  • C++ HELP I need help with this program. I have done and compiled this program in...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...

  • At this time, you need to create menu driven program. The menu includes the following list....

    At this time, you need to create menu driven program. The menu includes the following list. The menu should keep showing if a wrong choice is selected until one of the choices of 1 to 4 is selected. After each of the options 1 to 3 is done, the program shows the menu and waits for the user's choice. Upload your code here. 1. Add odd numbers from a to b 2. Add even numbers from a to b 3....

  • Create another program that will prompt a user for input file. The user will choose from...

    Create another program that will prompt a user for input file. The user will choose from 4 choices: 1. Display all positive balance accounts. 2. Display all negative balance accounts. 3. Display all zero balance accounts. 4. End program. C PROGRAMMING my code so far #include<stdlib.h> #include<stdio.h> int main(void) { int request; int account; FILE *rptr; char name[20]; double balance; FILE *wptr;    int accountNumber;    if((wptr = fopen("clients.dat","w")) == NULL) { puts("File could not be opened"); } else {...

  • Complete the functions for the program complex.c (Down) . The program adds, subtracts,and multiplies complex numbers....

    Complete the functions for the program complex.c (Down) . The program adds, subtracts,and multiplies complex numbers. The C program will prompt the user for the choice of operations,read in the complex numbers, perform the operations, and print the results. The main programrepeatedly prints the menu, reads in the user’s selection, and performs the operation. We use pointers only for those arguments that the function intends to change. In all thefunctions, r represents the real component and i represents the imaginary...

  • Here is the assignment: Fibonacci or Prime number iterator: Design a menu driven program that performs...

    Here is the assignment: Fibonacci or Prime number iterator: Design a menu driven program that performs the user’s choice of the following functions the program exits should also be a user’s choice. Menu Item 1: Fibonacci number iterator, here you are to define an iterator class named FibonacciIterator for iterating Fibonacci numbers. The constructor takes an argument that specifies the limit of the maximum Fibonacci number. For example, prompt the user for size, use the size to call FibonacciIterator(“user input”)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT