Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please change to code that allow user enter Y or y let user select menu, enter n or n let user exist and get the

please change to code that allow user enter Y or y let user select menu, enter n or n let user exist and get the total price, enter else letter will display " Please enter y or n." and ask user enter again.

here is my menu:

Plain Egg 2.45 Muffin 0.99 Bacon and Egg 2.99 French Toast 3.99 Fruit Basket 4.49 Cereal 0.69 Coffee 1.59 Tea 1.7

here is my code:

#include #include #include #include using namespace std;

//Structure to hold each menu item struct MenuItem { string menuName; double menuPrice; }; //Function that reads data from file void getData(struct MenuItem menuList[]); //Function that displays menu void showMenu(struct MenuItem menuList[]); //Function that reads user selection int makeSelection(int item[], int quantity[]); //Function that calculates the price void priceCheck(struct MenuItem menuList[], int item[], int quantity[], int items); //Main function int main() { struct MenuItem menuList[8]; int item[20], quantity[20]; int totalItems; //Reading data getData(menuList); //Displaying menu showMenu(menuList); //Making user selection totalItems = makeSelection(item, quantity); //Checking price priceCheck(menuList, item, quantity, totalItems); cout << " "; return 0; }

//Function that reads data from file void getData(struct MenuItem menuList[]) { //Opening file for reading fstream fin("menu.txt", ios::in); int i = 0; struct MenuItem temp; //Loop till entire data is processed while (fin.good()) { //Getting Menu Name getline(fin, temp.menuName); if (temp.menuName == "") { break; } //Reading menuPrice fin >> temp.menuPrice; fin.ignore(); //Storing in array menuList[i] = temp; i++; } //Closing file fin.close(); } //Function that displays menu void showMenu(struct MenuItem menuList[]) { int i; cout << " Welcome to Johnny's Restaurant --------Today's Menu-------- "; //Looping over menu and printing to user for (i = 0; i < 8; i++) { //Printing menu item cout << fixed << setprecision(2); cout << " " << (i + 1) << ". " << left << setw(20) << menuList[i].menuName << left << setw(2) << "$ " << left << setw(10) << menuList[i].menuPrice; } cout << " "; } //Function that reads user selection int makeSelection(int item[], int quantity[]) { int i = 0, temp; char ch; //Prompting user cout << " Do you want place an order? (y/n): "; cin >> ch; //Loop till user wants to stop if (ch == 'y' || ch == 'Y') { //Reading item number cout << " Enter item number: "; cin >> temp; //Storing in array item[i] = temp; //Reading item quantity cout << " Enter item quantity: "; cin >> temp; //Storing in array quantity[i] = temp; //Prompting user again cout << " Select another item? (y/n): "; cin >> ch; i++; } else if (ch == 'n' || ch == 'N') { return i; } else { cout << "Please enter y or n" << endl; makeSelection(item, quantity); } return i; } //Function that calculates the price void priceCheck(struct MenuItem menuList[], int item[], int quantity[], int items) { int i = 0; double total = 0, tax; cout << " Thank you for eating at Johnny's Restaurant "; cout << fixed << setprecision(2); //Printing menu selected for (i = 0; i < items; i++) { cout << " " << left << setw(5) << quantity[i] << left << setw(20) << menuList[item[i] - 1].menuName << left << setw(2) << " $ " << left << setw(2) << (quantity[i] * (menuList[item[i] - 1].menuPrice)); total += (quantity[i] * (menuList[item[i] - 1].menuPrice)); } //Calculating tax tax = (5 / 100.0) * total; //Printing tax cout << " " << left << setw(20) << " Tax " << left << setw(2) << " $ " << left << setw(2) << tax; //Printing total amount due cout << " " << left << setw(20) << " Amount Due " << left << setw(2) << " $ " << left << setw(2) << (total + tax) << " "; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

What is a financial feasibility analysis?

Answered: 1 week ago