Adding Choice From a Menu (Arrays, Structs)
Apr 25, 2014 at 9:36pm UTC
I need to write a program with a restaurant menu that allows users to choose more than one of an item. How do I add their choices to their order? AKA what should I put in the if (menuchoice ==1) spot?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int NUMITEMS = 8;
const double TAX = .05;
struct menuItemType
{
string item;
double price;
int quant;
};
/*****
Function: getData
Preconditon: none
Postcondition: gets menu data from a file
Date Coded: 4/25/14
*****/
void getData (ifstream& fin, menuItemType menu[], int & numItems);
/*****
Function: showMenu
Precondition: getData
Postcondition: shows items and allows selection
Date Coded: 4/25/14
*****/
int mymenu();
/*****
Function: printCheck
Precondition: getdata
Postcondition: calculates tax and prints check
Date Coded: 4/25/14
*****/
double printCheck (TAX);
int main ()
{
menuItemType menu[NUMITEMS];
menuItemType order[NUMITEMS];
int numItems = 0, menuchoice;
ifstream fin;
ofstream fout;
fin.open("menu.txt" );
getData (fin, menu, numItems);
cout << "Welcome to Johnny's Restaurant" << endl;
do
{
menuchoice = mymenu();
if (menuchoice == 1)
{
}
}while (menuchoice != 9);
return 0;
}
void getData (ifstream& fin, menuItemType menu[], int & numItems)
{
do
{
getline(fin, menu[numItems].item);
fin >> menu[numItems].price;
fin.get();
numItems++;
}
while (!fin.eof());
return ;
}
int mymenu()
{
int choice;
cout << left << "1. Plain Egg" << right << setw(5) << "$1.45" << endl
<< left << "2. Bacon and Egg" << right << setw(5) << "$2.45" << endl
<< left << "3. Muffin" << right << setw(5) << "$0.99" << endl
<< left << "4. French Toast" << right << setw(5) << "$1.99" << endl
<< left << "5. Fruit Basket" << right << setw(5) << "$2.49" << endl
<< left << "6. Cereal" << right << setw(5) << "$0.69" << endl
<< left << "7. Coffee" << right << setw(5) << "$0.50" << endl
<< left << "8. Tea" << right << setw(5) << "$0.75" << endl
<< left << "9. Exit Menu" << endl;
cin >> choice;
return choice;
}
Topic archived. No new replies allowed.