Structs and Arrays to program a menu
Mar 23, 2014 at 7:27pm UTC
Entire code so far provided but I need help with the showmenu function. Once it's established that a certain item has been selected (thus set to "true"), what then? Afterward I need to be able to display the bill listing each item and its cost and the total cost along with tax.
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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const double TAX = .08;
struct menuItemType
{
string menuItem;
double menuPrice;
bool selected;
};
void getdata(ifstream& infile, menuItemType menu[]);
int main()
{
menuItemType menu[20];
ifstream infile;
infile.open("menu.txt" );
getdata(infile, menu);
//call showmenu
//call printcheck
infile.close();
system("pause" );
return 0;
}
void getdata(ifstream& infile, menuItemType menu[])
{
int i = 0;
do
{
getline(infile, menu[i].menuItem);
infile >> menu[i].menuPrice;
infile.get();
menu[i].selected = false ;
i++;
} while (infile);
}
void showmenu(menuItemType menu[])
{
int choice;
int i;
cout << "Menu Choices" << endl;
cout << " 1. Plain Egg $1.45" << endl;
cout << " 2. Bacon and Egg $2.45" << endl;
cout << " 3. Muffin $0.99" << endl;
cout << " 4. French Toast $1.99" << endl;
cout << " 5. Fruit Basket $2.49" << endl;
cout << " 6. Cereal $0.69" << endl;
cout << " 7. Coffee $0.50" << endl;
cout << " 8. Tea $0.75" << endl;
cout << " 9. Finished Ordering" << endl;
cout << endl;
do
{
cout << "Enter a choice (1-8): " ;
cin >> choice;
menu[choice-1].selected = true ;
if (menu[i].selected == true )
{
}
} while (choice != 9);
}
void printcheck()
{
}
Topic archived. No new replies allowed.