Cashier program

How to get the sum number from total column?
For example first loop total=100, sum=100
second loop total=150, sum=250
third loop total=80, sum=330...
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
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int i=1, x=1, id;
    float   quantity, price, total=0, sum;
    string name;
    char enter, tick;
    cout << "#" << " ID " << "Name" << " Quantity " << "Price" << " Total" << endl;
    do{
    cin >> id;
    cin >> name;
    cin >> quantity;
    cin >> price;
    cout <<"#" << x++ << " " << id << " " << name << " " << quantity << " " << price << " " << quantity*price << endl;
    sum=quantity*price;
    cout << "                      " << sum++ << endl;
    cin >> tick;
    }while(tick == 't');

    return 0;
}
Last edited on
maybe add total += sum; just after line 19.
Your question is not clear.
Are you trying to get the total of all the values on "sum" variable?

l think the answer by Chervil can help in some way.

Reword your question or say what you want the code to do.
@Chervil
If i write like you said->

error: invalid operands of types 'float' and '<unresolved overloaded function type>' to binary 'operator<<'|

And how can i add precision in float variables, i tired this ->
<< setprecision(3)<< it said setprecision was not declared in this scope
tried this ->
<< std::setprecision(3) << it said setprecision is not member of 'std'
Last edited on
I don't know what you did to get that error. My suggestion was like this:
19
20
21
    sum = quantity*price;
    total += sum;
    cout << "                      " << sum++ << endl; 


If the error persists, please post your latest code which gives the error.

To use setprecision, you need #include <iomanip> .
Or use the syntax cout.precision(3);
http://www.cplusplus.com/reference/iomanip/setprecision/
http://www.cplusplus.com/reference/ios/ios_base/precision/
@Chervil
thanks for #include <iomanip>
i want to set precision after decimal dot.
found googling << fixed

thanks for
1
2
sum = quantity*price;
    total += sum;

i learned that i cant put {formulas=variable} in output, but in line yes
Last edited on
Topic archived. No new replies allowed.