### 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.
 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 #include #include #include #include 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.