your while statement is probably causing the problem. i've snipped out some huge sections of code and moved the looping around a little bit, resulting in the following for the main routine:
CODE
int main() {
ifstream fin;
string name;
char letter1, letter2;
double num;
double total1, total, total2, total3;
double more;
float price;
int menu, more1, Inum1, Inum;
num = .05;
total3 = 0;
total = 0;
total1 = 0;
total2 = 0;
fin.open("grocery_item.txt", ios::in);
if (!fin.good()) {
cout << "Error loading grocery_item.txt";
return 1;
}
do {
display_menu();
cin >> menu;
if (menu == 1) {
fin.seekg(0); //resets 'get' pointer to start of file
cout << "What is the item number";
cin >> Inum1;
do {
fin >> Inum >> name >> letter1 >> letter2 >> price;
} while (Inum != Inum1);
cout << "Item chosen is: "<< name << endl;
// DO YOUR PRICING STUFF HERE
}
} while (menu != 0);
fin.close();
cout << "Have a nice day!!"<< endl;
system("PAUSE");
return 0;
}
after the user selects menu option 1, the file pointer is set to the beginning of the file - very important if the last item selected is after the one the user is going to select. after getting the item number, the do-while loop reads in a line of data from the file, until the appropriate item number is found. then you would do your pricing stuff.
for future projects, you may want to take the incremental approach. the critical aspect here is file i/o and searching, so get that part of the algorithm set before you add in any of the operations that you are going to perform on the inputted data.
hope that helps.
-jjh