Question

In: Computer Science

Write a C++ code to print to the user a simple menu of a fast food...

Write a C++ code to print to the user a simple menu of a fast food restaurant. You should allow the user to select his/her preferred burgers and/or drinks and you should display the final bill to the user for payment. The user should be able to select more than one item. You should use the switch statement.

Solutions

Expert Solution

// Here is the tested and working CODE with attached output for your question :

#include<iostream>
#include<iomanip>
using namespace std;
int main(){
  
   // Arrays of Food Item and Respective Price
   const char *foodItems[] = {"Veg Burger","Non-Veg Burger","Diet Coke","Lime Water"};
   const double priceOfItems[] = {20.0, 40.0, 30.0, 10.12};
  
   // Variable to store the total bill
   double totalBill = 0.0;

   // Total number of items in the menu
   int totalItems = sizeof(foodItems)/sizeof(foodItems[0]);
  
   cout<< "Here is the Menu of the restaurant\n\n";
   cout<<left<<setw(10)<<setfill(' ')<<"Item No \t\t";
   cout<<left<<setw(20)<<setfill(' ')<< "Food Item \t\t";
   cout<<left<<setw(20)<<setfill(' ')<< "Price";

   cout<<endl<<endl;
   for(int i=0;i<totalItems;i++){
       cout<<left<<setw(10)<<setfill(' ')<<(i+1)<<" \t\t";
       cout<<left<<setw(20)<<setfill(' ')<<foodItems[i]<<" \t\t";
       cout<<left<<setw(20)<<setfill(' ')<<priceOfItems[i]<<endl;\
   }

   int choice;
   do {
       cout<<"Enter the item number you want to purchase and press 0 once done \n";
       cin>> choice;
       if(choice<0 || choice>(totalItems+1)){
           cout<<"Invalid Input. Please enter the item number correctly.";
           cin>>choice;
       }
      
       switch(choice){
           case 1:
               cout<<"Selected Item : "<<foodItems[0] <<" \t\t\t Price : "<<priceOfItems[0]<<endl<<endl;
               totalBill += priceOfItems[0];
               break;
           case 2:
               cout<<"Selected Item : "<<foodItems[1] <<" \t\t Price : "<<priceOfItems[1]<<endl<<endl;
               totalBill += priceOfItems[1];
               break;
           case 3:
               cout<<"Selected Item : "<<foodItems[2] <<" \t\t\t Price : "<<priceOfItems[2]<<endl<<endl;
               totalBill += priceOfItems[2];
               break;
           case 4:
               cout<<"Selected Item : "<<foodItems[3] <<" \t\t\t Price : "<<priceOfItems[3]<<endl<<endl;
               totalBill += priceOfItems[3];
               break;
           default :
               break;

       }
   } while(choice != 0);
   cout<<"\nTotal Bill = "<<totalBill<<endl;
}

//SAMPLE OUTPUTS


Related Solutions

print a menu so that the user can then order from that menu. The user will...
print a menu so that the user can then order from that menu. The user will enter each item they want until they are done with the order. At the end you will print the items the user ordered with their price and the total. Note: You will be storing your menu items (pizza, burger, hotdog, salad) and your prices (10, 7, 4, 8) in separate lists. Menu 0) pizza $10 1) burger $7 2) hotdog $4 3) salad $8...
C++ CODE Change your code from Part A to now present a menu to the user...
C++ CODE Change your code from Part A to now present a menu to the user asking them for an operation to perform on the text that was input. You must include the following functions in your code exactly as provided. Additionally, you must have function prototypes and place them above your main function, and the function definitions should be placed below the main function. Your program should gracefully exit if the user inputs the character q or sends the...
A. Write a C++ with a menu (using switch) that asks the user to select one...
A. Write a C++ with a menu (using switch) that asks the user to select one of the following choices to the user: 1. Options ‘S’ or ‘s’ 2. Option ‘T’ or ‘t 3. Options ‘P’ or ‘p’ 4. print in the Matrix format B. When 1 is selected, prompt the user to enter the starting value st (int value). Use a single FOR loop to count numbers from 1 to st. When the loop is finished, find the average...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an earthquake is in the range [0, 3), “medium” if M is in the range [3, 6), “large” if M is in the range [6, 9) and “epic” if M is greater than or equal to 9, where M is input by a user via the keyboard. (in c++)
C++ Write the C++ code for a void function that prompts the user to enter a...
C++ Write the C++ code for a void function that prompts the user to enter a name, and then stores the user's response in the string variable whose address is passed to the function. Name the function getName.
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
LANGUAGE: C Only using <stdio.h> & <stdlib.h> Write a program that gives the user a menu...
LANGUAGE: C Only using <stdio.h> & <stdlib.h> Write a program that gives the user a menu to choose from – 1. Convert temperature input from the user in degrees Fahrenheit to degrees Celsius 2. Convert temperature input from the user in degrees Celsius to degrees Fahrenheit 3. Quit. Formulae you will need: C = (5 / 9) * (F-32) and F = (9/5) * C + 32 1. Use functions to accomplish 1 and 2 above. 2. Use at least...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
*Please write code in C++* Write a program to verify the validity of the user entered...
*Please write code in C++* Write a program to verify the validity of the user entered email address.   if email is valid : output the stating that given email is valid. ex: "The email [email protected] is valid" else : output the statement that the email is invalid and list all the violations ex:  "The email sarahwinchester.com is invalid" * @ symbol * Missing Domain name The program should keep validating emails until user enter 'q' Upload your source code. ex: main.cpp
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT