In: Computer Science
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.
// 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