inventory program

PLEASE HELP ME FILL UP THE REST. I DONT KNOW WHAT TO PUT INSIDE THE WHILE LOOP
THE FIRST WHILE LOOP:
THE USER SHOULD ENTER THE INVENTORY.TXT WHICH CONTAINS (HAMMER, NAILS AND ITS COST)

SECOND WHILE LOOP:
//USER WILL ENTER OUTPUTFILE.TXT WHICH CONTAINS THE OUTPUT OF THE PROGRAM


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

using namespace std;

int main()
{
cout << "******************************************************************\n";
cout << "This program will create an inventory report where input file has \n";
cout << "the following data dormat (one record per line). \n\n";
cout << "Part_Name Number_Of_Units Unit_Price \n\n";
cout << "Please notice that part name is a single word";
cout << "********************************************************************";

ifstream input;
char ch= ' ';
bool done = false;
string inFile = "";
string output, inventory;

while (!done)
{
//WHAT CONDITION/ STATEMENTS SHOULD I PUT HERE
// THE USER SHOULD ENTER THE INVENTORY.TXT WHICH CONTAINS (HAMMER, NAILS AND ITS COST)
}

cout << "File " << inFile << " Opened successfully and has data in it \n";

ofstream out;
done = false;
string name;

while (!done)
{
//WHAT CONDITION/ STATEMENTS SHOULD I PUT HERE
//USER WILL ENTER OUTPUTFILE.TXT WHICH CONTAINS THE OUTPUT OF THE PROGRAM
}

cout << "\n Reading data file .......\n\n";

ostringstream os;
os<< fixed << showpoint << setprecision(2);


os << "*********************************************\n";
os << " Inventory Report \n";
os << "*********************************************\n";
os << endl;

double inv_total = 0.0;
ch = ' ';
while((ch = input.peek()) != EOF)
{
string name = "";
int units = 0;
double cost = 0.0;

input >> name;
input >> units;
input >> cost;

os << left << setw(9) << name;
os << right << setfill (' ') << setw(15) << units
<< setfill(' ') << setw(25) << cost
<< setfill (' ') << setw(20) << units * cost;
inv_total+=units * cost;
os << endl;
}

cout << endl << endl << endl;

os << "---------------------------------------------\n";
os << "Inventory TOtal ($) " << inv_total << endl;
os << "---------------------------------------------\n";

out << os.str();
cout << os.str();
cout << "Finished writitng to output file . \n\n";

input.close();
out.close();


return 0;
}
just psudo code it. only way is to get your hands dirty. lay it out.
Note: this code will not work cause its psudo code so don't compile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//the loop to continue the list of items
while(exit=0)
{
cout<<"product\n"; //ask for
cin>>product;
cout<<"cost\n"; //ask for
cin>>cost;   

//then save to txt file \n
//exit while loop menue
cout<<"0 to exit 1 to Add";
cin>>exit;
if(exit > 1)
{
cout<<"error wrong input input";
exit =0;
}

}

srry its the best i can do for you. today.
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
//USER WILL ENTER OUTPUTFILE.TXT WHICH CONTAINS THE OUTPUT OF THE PROGRAM


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

using namespace std;

int main()
{
cout << "******************************************************************\n";
cout << "This program will create an inventory report where input file has \n";
cout << "the following data dormat (one record per line). \n\n";
cout << "Part_Name Number_Of_Units Unit_Price \n\n";
cout << "Please notice that part name is a single word";
cout << "********************************************************************";

ifstream input;
char ch= ' ';
bool done = false;
string inFile = "";
string output, inventory;

while (!done)
{
//WHAT CONDITION/ STATEMENTS SHOULD I PUT HERE
// THE USER SHOULD ENTER THE INVENTORY.TXT WHICH CONTAINS (HAMMER, NAILS AND ITS COST)
}

cout << "File " << inFile << " Opened successfully and has data in it \n";

ofstream out;
done = false;
string name;

while (!done)
{
//WHAT CONDITION/ STATEMENTS SHOULD I PUT HERE
//USER WILL ENTER OUTPUTFILE.TXT WHICH CONTAINS THE OUTPUT OF THE PROGRAM
}

cout << "\n Reading data file .......\n\n";

ostringstream os;
os<< fixed << showpoint << setprecision(2);


os << "*********************************************\n";
os << " Inventory Report \n";
os << "*********************************************\n";
os << endl;

double inv_total = 0.0;
ch = ' ';
while((ch = input.peek()) != EOF)
{
string name = "";
int units = 0;
double cost = 0.0;

input >> name;
input >> units;
input >> cost;

os << left << setw(9) << name;
os << right << setfill (' ') << setw(15) << units
<< setfill(' ') << setw(25) << cost
<< setfill (' ') << setw(20) << units * cost;
inv_total+=units * cost;
os << endl;
}

cout << endl << endl << endl;

os << "---------------------------------------------\n";
os << "Inventory TOtal ($) " << inv_total << endl;
os << "---------------------------------------------\n";

out << os.str();
cout << os.str();
cout << "Finished writitng to output file . \n\n";

input.close();
out.close();


return 0;
}


There, much easier to read now :)
@icestorm what should i put inside the while loop can you help me figure this out im still a beginner for this pls help me
Well, first open the file with ifstream input("inventory.txt")

try this video tutorial for details:

https://www.youtube.com/watch?v=EjJY7yA5SWw&list=PLAE85DE8440AA6B83&index=67

And for the while loops, tell me what exactly you are trying to do, so we can help you. Check out all of Bucky's tutorials on YouTube, he has a whole series for beginners :)
Last edited on
Topic archived. No new replies allowed.