Answer to Question #214059 in C++ for syahidah

Question #214059

Active Café is a newly launch restaurant in Telupid Town. The owner wants to hire a

programmer to develop an online ordering system. The codes, menus and prices are

shown in the table below.

CODE MEAL NAME PRICE (RM)

1 Chicken Fillet 15.00

2 Roasted Beef 20.00

3 Rib eye Fillet 30.00

CODE BEVERAGE NAME PRICE (RM)

S Syrup 1.50

L Lychee 2.80

C Coconut 3.50

Based on the requirement these are what the owner wanted the system to do.

i. The customer order the meal and beverage based on the code

ii. The system will ask the quantity for each order

iii. The system displays the quantity and the total price of the meal

iv. The system displays the quantity and the total price of the beverage

v. The system displays the total price that the user needs to pay

vi. The system will repeat the process i to v until user put ‘N’ to stop the program


1
Expert's answer
2021-07-06T08:19:33-0400
#include <iostream>
#include <string>
using namespace std;


int main () {
	string selectedItem="";
	float totalMealPrice=0;
	int totalQuantityMeal=0;
	float totalBeveragePrice=0;
	int totalQuantityBeverage=0;
	while(selectedItem!="N" && selectedItem!="n"){
		//CODE MEAL NAME PRICE (RM)
		//1 Chicken Fillet 15.00
		cout<<"1. Chicken Fillet - RM 15.00\n";
		//2 Roasted Beef 20.00\n";
		cout<<"2. Roasted Beef - RM 20.00\n";
		//3 Rib eye Fillet 30.00
		cout<<"3. Rib eye Fillet - RM 30.00\n";
		//CODE BEVERAGE NAME PRICE (RM)
		//S Syrup 1.50
		cout<<"S. Syrup - RM 1.50\n";
		//L Lychee 2.80
		cout<<"L. Lychee - RM 2.80\n";
		//C Coconut 3.50
		cout<<"C. Coconut - RM 3.50\n";
		cout<<"N. Stop the program\n";
		//vi. The system will repeat the process i to v until user put ‘N’ to stop the program
		cout<<"Your choice: ";
		//Based on the requirement these are what the owner wanted the system to do.
		//i. The customer order the meal and beverage based on the code
		getline(cin,selectedItem);
		if(selectedItem!="N"){
			int quantity=0;
			//ii. The system will ask the quantity for each order
			cout<<"Enter the quantity for order: ";
			cin>>quantity;
			if(selectedItem=="1"){
				totalMealPrice+=quantity*15.00;
				totalQuantityMeal+=quantity;
			}else if(selectedItem=="2"){
				totalMealPrice+=quantity*20.00;
				totalQuantityMeal+=quantity;
			}else if(selectedItem=="3"){
				totalMealPrice+=quantity*30.00;
				totalQuantityMeal+=quantity;
			}else if(selectedItem=="S"){
				totalBeveragePrice+=quantity*1.50;
				totalQuantityBeverage+=quantity;
			}else if(selectedItem=="L"){
				totalBeveragePrice+=quantity*2.80;
				totalQuantityBeverage+=quantity;
			}else if(selectedItem=="C"){
				totalBeveragePrice+=quantity*3.50;
				totalQuantityBeverage+=quantity;
			}else if(selectedItem=="N"){
				//stop the program
			}else{
				cout<<"\nWrong code.\n\n";
			}
			//iii. The system displays the quantity and the total price of the meal
			cout<<"\nThe quantity of the meal: RM "<<totalQuantityMeal<<"\n";
			cout<<"The total price of the meal: RM "<<totalMealPrice<<"\n";
			//iv. The system displays the quantity and the total price of the beverage
			cout<<"The quantity of the beverage: RM "<<totalQuantityBeverage<<"\n";
			cout<<"The total price of the beverage: RM "<<totalBeveragePrice<<"\n";
			//v. The system displays the total price that the user needs to pay
			float totalPrice=totalMealPrice+totalBeveragePrice;
			cout<<"The total price that the user needs to pay: RM "<<totalPrice<<"\n\n";
			cin.ignore();
		}
	}

	system("pause");
	return 0;
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS