Reputation: 431
In this program, I prompt the user to enter the product code and the quantity. I use a do...while loop to show it. How to I sum the all totals of every loop? For example, the user enter the code as 1, quantity as 2, the the program will calculate the total, and remember it. The next time the user enter another code and quantity, the new total will be the old total + the current total.
Upvotes: 0
Views: 131
Reputation: 150108
Right under where you declare the option
variable, add a total
variable
int option = 0;
int total = 0;
Then right under where you get the additional quantity, also increment the total
scanf_s("%d", &quantity);
total += quantity;
Upvotes: 3