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...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user...
Write a program names EncryptDecrypt.java that has the following menu choices: Print menu and allow user to choose options. The program must have a file dialogue box for text file. Output should be based on user choices. Read in a file Print the file to the console Encrypt the file and write it to the console Write out the encrypted file to a text file Clear the data in memory Read in an encrypted file Decrypt the file Write out...
Write a c++ code that prompts the user to enter three float numbers and print them...
Write a c++ code that prompts the user to enter three float numbers and print them in acsending order
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...
java code Write a program that gives the user a menu of six choices (use integers)...
java code Write a program that gives the user a menu of six choices (use integers) to select from. The choices are circle, triangle, cone, cylinder, sphere, and quit. (The formulas are given below.) Once the figure is calculated, an informative message should be printed and the user shown the menu again, so that another choice can be made. The formulas are: Area of circle: a = 3.14 * radius * radius Area of triangle: a = ½ base *...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT