help with output file

Almost completed this assignment. It's a store program that uses structures to save and manipulate data that has been inputted from a text. At the end of the sign out, we are supposed to output the adjusted inventory amounts into a new text document.I am able to adjust the units of inventory for the items with which the user has selected to purchase. however for the items that have not been used at all, instead of outputting the orignial amounts of each item (item[].storage), the computer outputs to the file 0's. Any help would be greatly appreciated.

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* 
 * File:   main.cpp
 * Author: Chip
 * Created on September 28, 2012, 8:31 AM
 */

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

using namespace std;

const int PRODUCT = 100;

struct Item {
    double plucode;
    string name;
    double incremint;
    double price;
    double storage;
    double inventory;
    double invent;
};


double userPounds, userPrice, userDiscount, userTotal, userInput, userTotalPounds, userFinal;
int number = 0;
int i = 0;
bool trueValue, falseValue;
char again, sign, done;
int currentItem;

int main(int argc, char** argv) {

    ifstream inputFile("Inventory.txt");

    ofstream outputFile;
    outputFile.open("output.txt");

    sign = 'y', 'Y', 'n', 'N';
    again = 'y', 'Y', 'n', 'N';

    Item item[100];

    while (!inputFile.eof()) {

        inputFile >> item[number].plucode >> item[number].name >> item[number].incremint >> item[number].price >> item[number].storage;
        number++;
    }
    inputFile.close();

    bool done = false;

    cout << "Welcome to Simple Store" << endl;

    while (done == false) {
        do {
            do {

                cout << "Enter plucode of the item that you wish to purchase.";
                cin >> userInput;

                for (int i = 0; i < PRODUCT; i++) {
                    if (userInput == item[i].plucode) {
                        currentItem = i;
                    }
                }
                cout << "How many units of " << item[currentItem].name << " would you like?" << endl;
                cin >> userPounds;
                
                for (int i = 0; i < 21; i++) {
                    if (userPounds >= 0) {
                        item[currentItem].inventory = (item[currentItem].storage - userPounds);
                    } else item[currentItem].inventory = item[currentItem].storage;
                }
                
                userPrice = item[currentItem].price * userPounds;

                cout << "The price would be $" << userPrice << endl;

                userTotal += userPrice;
                userTotalPounds += userPounds;

                if (userTotal > 50) {
                    userFinal += userTotal * .95;
                    userDiscount += userTotal * .05;
                }

                cout << "Would you like to check out? (Y/N)" << endl;
                cin >> again;

                if (again == 'N' || again == 'n') {
                    cout << "Proceed to next item" << endl;
                }

            } while (again == 'N' || again == 'n');

            cout << "Would you like to sign out? (Y/N)" << endl;
            cin >> sign;
            if (sign == 'Y' || sign == 'y') {
                cout << setprecision(2) << fixed;
                cout << "Your total weight sold was " << userTotalPounds << " units." << endl;
                cout << "Your total gross sales amount is $" << userTotal << endl;
                cout << "Your final checkout amount is $" << userFinal << endl;
                cout << "Your total discounts given were $" << userDiscount << endl;
                done == true;
            }

        } while (sign == 'N' || sign == 'n');

        for (i = 0; i < 21; i++)
            outputFile << item[i].plucode << " " << item[i].name << " " << item[i].incremint << " " << item[i].price << " " << item[i].inventory << endl;

        outputFile.close();

        cout << "Program is being terminated";
        break;
    }
}
In line 113 you have while i < 21; Shouldn't it be while i < (user entries)?
In other words, how do know what they entered is exactly 21 items? If they entered in 11 items then the final 10 items would get something output to them which you do not want.

I'm not 100% sure, but that's my initial guess.
Topic archived. No new replies allowed.