Read in only text from file not numbers

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



Last edited on
What do you want the function getdat to do vs getdata?
What output do you expect?
I think you want to have both getdat and getdata like:
1
2
void getdata(menuItemType menu[], int &i);
void getdat(menuItemType menu[], int &i);

So when you come back from getdat or getdata the value of i will have the number of elements in the array menu. Just remember if you call both the number i will get incremented twice.
Topic archived. No new replies allowed.