inventory program. PLEASE HElp

Hi, I'm really stuck with this program and this assignment is due tomorrow. I would really appreciate if someone can help me. For the assignment i had to 1.create a text file, 2. declare a stream, 3. open my text file, 4. check that the open did not fail, 5.display the name of my store, 6. read the inventory from a file into arrays- the item number, quantity of the item, and name of the item. the program should read the whole file, no matter how many items are in it. 7. In a loop until the user enters STOP, it should display the item number and name on the screen. and ask the user what he or she would like to buy and how many. If the user orders more than in inventory- error message. 8. close the stream, and 9. print the final inventory. Now i wrote the program but it's unable to open the file and i'm not able to do parts 6 and 7. PLEASE HELP ME. THank you!
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

#include<fstream>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<string>

using namespace std;


int main()
{
	ifstream fin ("inventory.txt");
	int amount;
	char end;
	int item_number[30], quantity[30];
	char name[30];
	string line;


	if (fin.is_open())
	{
		while (!fin.eof())
		{
			getline (fin,line); 
            
        }
	}
    else cout << "Unable to open file";
	


	cout<<"\n\n" << "Grocery Shop!"<<"\n\n";

	cout<<setw(15) << "ITEM #"<< setw(11) << "Item Name" << setw(12) << "Quantity \n";
	
	for (int i=0; i<30; i++)
		
		cout<<item_number[i]<<" "
			<<quantity[i]<<endl;

	
		for (char n=0; n<30; n++)
			cout<<name[n]<<endl;
		do
		{
			
			cout<<endl
				<<"What would you like to buy and how many?";
			cin>>name>>amount;
			if (amount>quantity[0])
			{
				cout<<" Error - Out of Stock";
			}
			else
			{
				cout<< amount;
			}

			cout<<endl;
		cout<<"Type STOP to end the program.\n";
		cin>>end;
		} while((end == 'STOP')&& (end=='stop'));

		fin.close();

	return 0;
}


My text file is like this

10
50
Apples

11
60
Oranges

12
40
Grapes

13
45
Bananas

14
50
Mangoes


You are declaring the variable end as a character variable, but are asking the user to input a string, "stop", 'stop' is not a valid character. Change the variable type to string, and replace the ' around the conditionals with double "
Topic archived. No new replies allowed.