Loops, structures and file manipulation// Help.

So I have a program to do that requires me to check the inventory a super market file and test it with another file that holds a 4 digit code. I am suppose to get the 4 digit code from one file and test it against the product code in the inventory file. I'm only allowed to use structures, arrays and file manipulation. i stored both of the information in arrays already but i cant seem to find a way to search the inventory array for the 4 digit code that is in my orders array and start the process over for the next bit of information in the orders array. Please help if you can and give tips of how to neaten up the program. I know i was terrible at explain this. :/
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
 #include <iostream>
#include <fstream>
#include <string>

using namespace std;

struct invent {
int proCode;
string descrip;
float price;
int Quantity;
};

int main () {
ifstream userOrder;
ifstream inventFile;
invent inventory [999];
int orders [999];
userOrder.open("User Order.txt", ios::app);
inventFile.open("Supermarket Inventory.txt", ios::app);

if (!userOrder.is_open()) {
    cerr << "The file was not opened." << endl;
}
if (!inventFile.is_open()) {
    cerr << "The file was not opened." << endl;
}

for (int x = 0; !inventFile.eof(); x++) {
    inventFile >> inventory[x].proCode;
    inventFile >> inventory[x].descrip;
    inventFile >> inventory[x].price;
    inventFile >> inventory[x].Quantity;
}
for (int x = 0; !userOrder.eof(); x++) {
    userOrder >> orders[x];
}

}
Last edited on
Topic archived. No new replies allowed.