Hi, I'm trying to create my first program however, I ran into a deadend. I want to send the value from the switch statement all the way to main. I've tried using return statements, but I don't think that's the right way to do it.
I hope that made sense.
/*
A program which runs a simple restaurant order.
*/
#include <iostream>
usingnamespace std;
void menu()
{
void drink();
int choice;
int burger = 15.00;
int wings = 7.00;
int steak = 16.50;
int stew = 11.00;
int sub = 14.00;
cout << endl;
cout << "Here's the menu please decide what you'd like.\n";
cout << "1. Classic Joe Burger: 15.00\n";
cout << "2. Buffalo Wings: 7.00\n";
cout << "3. Classic Joe Steak: 16.50\n";
cout << "4. Beef Stew: 11.00\n";
cout << "5. Supreme Sub: 14.00\n\n";
cout << "What is your choice: ";
cin >> choice;
switch (choice)
{
case 1:
cout << "You chose the Classic Joe Burger! What would you like to drink?\n";
return burger;
drink();
break;
case 2:
cout << "You chose the Buffalo Wings! What would you like to drink?\n";
return wings;
drink();
break;
case 3:
cout << "You chose the Classic Joe Steak! What would you like to drink?\n";
return steak;
drink();
break;
case 4:
cout << "You chose the Beef Stew! What would you like to drink?\n";
return stew;
drink();
break;
case 5:
cout << "You chose the supreme sub! What would you like to drink?\n";
return sub;
drink();
break;
default:
cout << "That's not on the menu!";
}
}
void drink()
{
int beer = 5.50;
int choice2;
cout << "Here is the list of Beers available. Each bottle is 5.50.\n";
cout << endl;
cout << "1. Budweiser\n";
cout << "2. Heineken\n";
cout << "3. Efes Pilsen\n";
cout << "4. Corona Extra\n";
cout << "5. San Miguel Pale Pilsen\n";
cout << "6. Guinness\n";
cout << "7. Miller Lite\n";
cout << endl;
cout << "What is your choice: ";
cin >> choice2;
switch(choice2)
{
case 1:
cout << "You chose the Budweiser.";
return beer;
break;
case 2:
cout << "You chose the Heineken.";
return beer;
break;
case 3:
cout << "You chose the Efes Pilsen.";
return beer;
break;
case 4:
cout << "You chose the Corona Extra.";
return beer;
break;
case 5:
cout << "You chose San Miguel Pale Pilsen.";
return beer;
break;
case 6:
cout << "You chose Guinness.";
return beer;
break;
case 7:
cout << "You chose Miller Lite.";
return beer;
break;
default:
cout << "I'm sorry but that was not a choice.";
}
}
int main()
{
char o;
cout << "Welcome to Joe's Restaurtant & bar!\n";
cout << "Would you like to order?.\n";
cout << "Y/N? ";
cin >> o;
if (o == 'Y')
menu();
elseif (o == 'N')
cout << "Oh, Goodbye.\n";
else
cout << "I don't understand.\n";
cout << "Your total comes out to: $" << choice + beer << ". Please enjoy your meal!";
return 0;
}
You routines are listed as void meaning they do not return and datatypes that you can use.
Change the void to whatever datatype you want to return. Since Beer and Stew are both ints change their headings to
int menu() & int drink()
Edit - Why are you declaring the drink(); routine inside the menu routine on line 9? Instead declare int menu(); andint drink; at the very top of your file and then move their implementation down below your main.