Mar 28, 2012 at 2:07am UTC
Here's the code. I'm reading in a menu from a .txt file. The "getdat" function is supposed to read in just text not numbers. any ideas? Show menu isn't needed in the picture just yet.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
struct menuItemType
{
string menuItem;
double menuPrice;
bool selected;
};
void getdata(menuItemType menu[], int i);
void getdat(menuItemType menu[], int i);
void printcheck();
int main()
{
int i = 0;
menuItemType menu[20];
getdata(menu, i);
getdat(menu,i);
system ("pause");
return 0;
}
void getdata(menuItemType menu[], int i)
{
ifstream infile;
infile.open("menu.txt");
i = 0;
do
{
getline(infile, menu[i].menuItem);
infile >> menu[i].menuPrice;
infile.get();
cout << menu[i].menuPrice << endl;
i++;
} while (infile);
infile.close();
}
void getdat (menuItemType menu[], int i)
{
ifstream infile;
infile.open("menu.txt");
string item;
i = 0;
do
{
getline(infile, menu[i].menuItem);
infile >> menu[i].menuItem;
cout << menu[i].menuItem << endl;
i++;
} while (infile);
infile.close();
}
void showmenu()
{
}
Here's the menu...
Plain Egg
1.45
Bacon and Egg
2.45
Muffin
0.99
French Toast
1.99
Fruit Basket
2.49
Cereal
0.69
Coffee
0.50
Tea
0.75