Below are the instructions and below that is my code..... Im having trouble adding functions to my switch statements.. Confused on how to pass the value for addOn and make it into a function to add to my switch sorry if my question is confusing In the code below ive added a do while loop and a void function to show the menu but passed that im pretty stuck
Thanks
*******************************
Begin with your corrected code from Program 5B: Restaurant Menu. (Be sure to see my solution and ensure that your code is accurate before you continue with this assignment.)
Extend your restaurant menu program to include:
a do-while loop which redisplays the menu so the user may continue to order additional items and ends when the user chooses to quit
Keep a running total of all items and add ons. That means you need a grand total and an item total variable.
You do NOT need to display an itemized list at the end. Once you learn more C++ skills you will add that feature. For now, simply display the grand total for all items ordered to the user at the end.
Your job is to redesign your code to use functions.
At a minimum, you must:
use functions to validate all user input
create overloaded isValid functions which return a boolean value
use isValid in a while loop or do-while loop to validate user input
use functions for each item menu, so that the switch statement calls a function for each case
similar to the Math Tutor program, display a menu and use a switch statement to call a function
For example, if your Menu consists of:
1. Blueberry Pie
2. Apple Pie
3. Peach Pie
4. Pumpkin Pie
5. Quit
Then create a function called blueberryPie to process the order, adding the cost of blueberry pie to the total and asking the user about 3 options to add on while totaling the price. NOTE: This is mostly a copy and paste of your existing code.
You will need to move constants from main into the function to ensure that the scope (visibility) is accurate OR pass them as parameters. Your choice.
You decide if you use void or value returning functions and if you use value or reference parameters in your functions or none at all.
//*******************************************************************
CODE
*****
// CIS 5 - Online
// Program 5A - Restauraunt Menu
// Date 9/28/2021
#include <iostream>
#include <iomanip>
#include<string>
#include <ctime>
#include <cstdlib>
using namespace std;
do { // do show menu while choice is not 5
showMenu();
cin >> choice;
switch (choice) // Int Choice switch per number chosen
{
case 1:
total = itemCost1;
cout << "Would you like to add extra seafood?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like extra sauce? ";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like to add extra bread?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Your total is, " << total;
break;
case 2:
total = itemCost1;
cout << "Would you like to add extra seafood?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like extra sauce? ";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like to add extra bread?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Your total is, " << total;
break;
case 3:
total = itemCost1;
cout << "Would you like to add extra seafood?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like extra sauce? ";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like to add extra bread?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Your total is, " << total;
break;
case 4:
total = itemCost1;
cout << "Would you like to add extra seafood?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like extra sauce? ";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
case 5:
cout << " Thanks for choosing Mrs Lovettes :] " << endl
<< "Where you are what you eat!";
cout << "Would you like to add extra bread?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Your total is, " << total;
break;
}
}while (choice != 5);
}
void showMenu() // Show menu function // Do show this menu while choice doesnt = 5 or quit
{
cout << "Mrs Lovettes Meat Pie Emporium" << endl << "Where you are what you eat!\n\n";
cout << "\n\nMenu\n\n";
cout << "1: Spinach Ravioli" << endl;
cout << "2: Shrimp Alfredo" << endl;
cout << "3: Lobster Thermidore" << endl;
cout << "4: Cut Throat Special" << endl << endl;
}
Ooh k thanks i usually do. And will remember to keep them in from now on.. any suggestions? i Just figured out how to call by value parameters in functions. Im having confusion figuring out how to use ref parameters in my functions
ie..
doubleFunctionName()
{
function definition
}
i usually do [use code tags] And will remember to keep them in from now on.. any suggestions?
No time like the present to use code tags. You can edit your post and add them now vs. waiting for another post. Even simple code snippets like the one in your 2nd post could benefit from having code tags.
I added code tags after the first time you suggested it. Still no help.. Its cool tho i figured it out hours later on my own. But what counts is i figured it out. Thanks 4n.
//*******************************************************************
CODE
***** // kbw: did you forget to comment this line?
// CIS 5 - Online
// Program 5A - Restauraunt Menu
// Date 9/28/2021
#include <iostream>
#include <iomanip>
#include<string>
#include <ctime>
#include <cstdlib>
usingnamespace std;
void showMenu(); // [MenuFunction]
int main()
{
int choice; // Menu options // Defined Variables
constdouble itemCost1 = 12.0,
itemCost2 = 17.0,
itemCost3 = 24.0,
itemCost4 = 25.0;
constdouble addOn = 03.99;
double total;
char answer;
const string item1 = "Spinach Ravioli";
const string item2 = "Shrimp Alfredo";
const string item3 = "Lobster Thermidore";
const string item4 = "Cut Throat Special";
do { // do show menu while choice is not 5
showMenu();
cin >> choice;
switch (choice) // Int Choice switch per number chosen
{
case 1:
total = itemCost1;
cout << "Would you like to add extra seafood?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like extra sauce? ";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like to add extra bread?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Your total is, " << total;
break;
case 2:
total = itemCost1;
cout << "Would you like to add extra seafood?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like extra sauce? ";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like to add extra bread?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Your total is, " << total;
break;
case 3:
total = itemCost1;
cout << "Would you like to add extra seafood?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like extra sauce? ";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like to add extra bread?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Your total is, " << total;
break;
case 4:
total = itemCost1;
cout << "Would you like to add extra seafood?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Would you like extra sauce? ";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
// kbw: did we forget the break statement?
case 5:
cout << " Thanks for choosing Mrs Lovettes :] " << endl
<< "Where you are what you eat!";
cout << "Would you like to add extra bread?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
total = total + addOn;
}
cout << "Your total is, " << total;
break;
}
} while (choice != 5);
}
void showMenu() // Show menu function // Do show this menu while choice doesnt = 5 or quit
{
cout << "Mrs Lovettes Meat Pie Emporium" << endl << "Where you are what you eat!\n\n";
cout << "\n\nMenu\n\n";
cout << "1: Spinach Ravioli" << endl;
cout << "2: Shrimp Alfredo" << endl;
cout << "3: Lobster Thermidore" << endl;
cout << "4: Cut Throat Special" << endl << endl;
}
case 1:
total = itemCost1;
cout << "Would you like to add extra seafood?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
addOn(total);
}
cout << "Would you like extra sauce? ";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
addOn(total);
}
cout << "Would you like to add extra bread?";
cin >> answer;
if (answer == 'Y' || answer == 'y')
{
addOn(total);
}
cout << "Your total is, " << total;
break;
You can also go further, by making each switch case a function:
int main()
{
int choice; // Menu options // Defined Variables
double total = 0.0;
do { // do show menu while choice is not 5
showMenu();
cin >> choice;
switch (choice) // Int Choice switch per number chosen
{
case 1:
total += orderSpinachRavioili();
break;
case 2:
total += orderShrimpAlfredo();
break;
case 3:
total += orderLobsterThermidor();
break;
case 4:
total += orderShrimpAlfredo();
break;
case 5:
cout << " Thanks for choosing Mrs Lovettes :] " << endl
break;
default: // kbw:all other inputs drop here
; // kbw: you may add some kind of message
}
cout << "Your total is, " << total << endl;
} while (choice != 5);
}