I'm having trouble with this, the question is listed in the code please somebody

#include <iostream>


//ask the user for a set of data, product price & amount. calculate the total cost of the product.
//cotinue to ask the user for different sets of data until th user wants to exit
// print the total cost for all the products he bought

int main(int argc, char** argv) {
using namespace::std;
int price, amount, total;



do {

cout << "Enter '0' to exit";
cout << endl;
cout << "Enter the price of the item";
cin >> price;
cout << "Enter the amount of the item you are purchasing";
cin >> amount;


total=price*amount;
cout << total;
}

while((num1 !=0) || (num2 !=0));

return 0;
}
If the user enters the integer 0 the program should immediately exit but I'm not sure how to do that.
I'm sorry I mad a mistake in the counter
it should be while ((price !=o) || (amount !=0))
1
2
cin >> price;
if( price == 0 ) break ;

thanks a lot @JLBorges


I would still need to know how to get the totals to ad every time the loop runs.

I was guessing it would be something loke
total=total+total

outside he while loop but before the counter but it was not correct
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
#include <iostream>

int main( /* int argc, char** argv */ )
{
    using namespace::std;

    int price;
    int amount;

    int total = 0 ; // initialise total to zero

    do
    {
        cout << "Enter '0' to exit\nEnter the price of the item: ";
        cin >> price;
        if( price == 0 ) break ;

        cout << "Enter the amount of the item you are purchasing: ";
        cin >> amount;

        const int subtotal = price * amount;
        cout << "subtotal: " << subtotal << '\n';

        total += subtotal ; // add subtotal to total
    }

    while( /* ( price != 0 ) || */ ( amount != 0 ) );

    std::cout << "grand total: " << total << '\n' ;

    //return 0;
}
Thank you so much @JLBorges You are a life saver
Topic archived. No new replies allowed.