Output code

so I wrote this code in class today and I'm almost done but I need to come up with some sort of equation to add up all the total values. The problem is I am reading data off a txt file so it's all being read as one thing. I don't know how to get each specific value and add them all together. This is my code so far.
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
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;

int main()
{
	string item;
	int amount;
	double price;
	double cost;
	double invTotal;
	ifstream in;
	in.open("input.txt");
	ofstream out; 
	out.open("output.txt");
	
	cout << fixed << setprecision(2);

	for (int j=0; j < 39; j++)
	{
		cout << " " << (char)220;
	}
	cout << "\n";
	cout << "\t\tInventory Report for Jane Doe International Hardware\n";
	for (int j=0; j < 39; j++)
	{
		cout << " " << (char)220;
	}
	
	cout << "\n"; 
	cout << "Item"; 
	cout << "\tNumber of Units";
	cout << "\t\tUnit Cost($)";
	cout <<  "\t\tTotal Value($)\n";

	for (int j=0; j < 79; j++)
	{
		cout << (char)196;
	}
	cout << "\n";



	while(!in.eof())
	{ in >> item >> amount >> price; 
	cost = amount * price;

	cout << left << setw(10)  << item
		 << right << setw(5) << amount 
		 << right << setw(25) << price 
		 << right << setw(30) << cost
		 << "\n";
	
	}

	for (int j=0; j < 79; j++)
	{
		cout << (char)196;
	}	
	cout << "\n";


	cout << "Inventory Total($):";



return 0;
}



here's what's inside the input file

Chisel 50 9.99
Hammer 30 15.99
Nails 2000 0.99
Bolts 200 2.99
Nuts 300 1.99
Soap 55 1.89

I end up multiplying the amount by the price to get the total value as shown in the code above. Now I just don't know how to add the total value of each item to get the total overall value. Also I haven't used invTotal because I want that to be the overall total.
Last edited on
track each total and add them to another total variable
whole_total += single_total;
This variable invTotal has not been used. Also, you should give an example of what is inside the file. I mean the format.

Topic archived. No new replies allowed.