Scenario:
The manager of the Diner by the Valley restaurant plans to have a computer available for students to place their orders when they enter the campus center. They have a limited menu selection available that includes sandwiches and drinks.
In addition to white bread, they have whole wheat and rye bread. No charge is included for different bread types; however, they do consider that selection a special request. The interface should enable special requests such as bread types to be selected. Students should be able to enter other special requests such as "Hold the onion" or "Hold the mayo". Water is available for each order at no charge, but it must be ordered. Prices are as follows: • Sandwich = $2.00 • Tea = $1.80, • Coffee = $2.30 • Juice = $1.50. The manager needs a user-friendly interface where a student can choose options easily and at the end, the program should display the current order selections and show the total cost of the order.
#include<iostream>
#include <string>
using namespace std;
string getWater(){
string water[]={"yes","no"};
int waterSelected=-1;
while(waterSelected<1 || waterSelected>2){
cout<<"Would you prefer water as well? (1 - yes, 2 - no): ";
cin>>waterSelected;
}
return water[waterSelected-1];
}
int main(){
const float SANDWICH = 2.00;
const float drinksCost[] = {1.80,2.30,1.50};
cout<<"Welcome to Diner by the Valley restaurant\n\n";
int ch=-1;
float totalCharge=0;
while(ch!=3){
cout<<"Please choose your menu items\n";
cout<<"1. Sandwich\n";
cout<<"2. Drinks\n";
cout<<"3. Exit\n";
cout<<"Choice: ";
cin>>ch;
if(ch==1){
string breadColors[]={"White","Wheat","Rye"};
int selectedBreadColors=-1;
while(selectedBreadColors<1 || selectedBreadColors>3){
cout<<"Please choose the bread type:\n";
cout<<"1. White bread\n";
cout<<"2. Wheat bread\n";
cout<<"3. Rye bread\n";
cout<<"Choice: ";
cin>>selectedBreadColors;
}
int specialRequest=-1;
string special[]={"Hold the onion","Hold the mayo","None"};
while(specialRequest<1 || specialRequest>3){
cout<<"Please choose your special request\n";
cout<<"1. Hold the onion\n";
cout<<"2. Hold the mayo\n";
cout<<"3. None\n";
cout<<"Choice: ";
cin>>specialRequest;
}
string water=getWater();
totalCharge+=SANDWICH;
cout<<"\n\nYour Order\n";
cout<<"Menu selected: Sandwich\n";
cout<<"Bread Type: "<<breadColors[selectedBreadColors-1]<<" bread\n";
cout<<"Special Request: "<<special[specialRequest-1]<<"\n";
cout<<"Water selected: "<<water<<"\n";
}else if(ch==2){
string drinks[]={"Tea","Coffee","Juice"};
int selectedDrink=-1;
while(selectedDrink<1 || selectedDrink>3){
cout<<"Please choose your drink:\n";
cout<<"1. Tea\n";
cout<<"2. Coffee\n";
cout<<"3. Juice\n";
cout<<"Choice: ";
cin>>selectedDrink;
}
string water=getWater();
totalCharge+=drinksCost[selectedDrink-1];
cout<<"\n\nYour Order\n";
cout<<"Menu selected: Drinks\n";
cout<<"Drink Type: "<<drinks[selectedDrink-1]<<"\n";
cout<<"Water selected: "<<water<<"\n";
}else if(ch==3){
//exit
}else{
cout<<"\nWrong menu item.\n\n";
}
cout<<"\nTotal charge is: $"<<totalCharge<<"\n\n";
}
int k;
cin>>k;
return 0;
}
Comments
Leave a comment