C++ Inventory Program Help

Hello, I'm new here! I need help with an inventory program I'm creating. I've finally set up everything to work but for some reason my numbers are not right justifying. I also just tried checking the ofstream file it created and it was empty. Not sure why. Id appreciate some help :)

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
#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

int main()

{
    // declare the stream varables here
    ifstream inFile;
    ofstream outFile;
    
    
    //declare variables to manipulate first

    string itemname = string();
    double numunits, unitprice, totalvalue, inventorytotal = double();
 
    
    // open the file here
    inFile.open("proj5inventory.txt");
    outFile.open("reportinventory.txt");

    cout << fixed << showpoint << setprecision(2);
    



    //******************the start of the header****************************//
    
    for (int i=1; i <= 50; i++)
    {
        cout << "\u25A0 ";
    }
    cout << endl;
    cout << "\t\t\t\t\t\tInventory Report For International Hardware Store" << endl;
    for (int i=1; i <= 50; i++)
    {
        cout << "\u25A0 ";
    }
    cout << endl;
    
    
    cout << setfill('.') << left << setw(35) << "ITEM             NUMBER OF UNITS             UNIT COST ($)             TOTAL VALUE($)" << endl;
    
    
    for (int i=1; i <= 97; i++)
    {
        cout << "_";
    }
    cout << endl << endl;
    
    
    //*****************end of header***********//
    
    
        
    while (!inFile.eof())
    {
        

        if(inFile.fail())
        {
        inFile.clear();
         
        }
        getline(inFile, itemname);
        inFile >> itemname;
        inFile >> numunits;
        inFile >> unitprice;

        totalvalue = unitprice * numunits;
        inventorytotal += numunits * unitprice;
        
        
        

        
       
        
        

        
        cout << left << itemname
        << setw(23) << right << setfill(' ') << numunits
        << setw(24) << right << setfill(' ') << unitprice
        << setw(28) << right <<  setfill(' ') << totalvalue <<  endl;

    }
    
    for (int i=1; i <= 97; i++)
    {
        cout << "_";
    }
    cout << endl << endl;
    cout << "Inventory Total($)                                                       " << inventorytotal << endl;
    
    
    inFile.close();
    outFile.close();
    

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