So I have a problem with looping. Not sure which one to use for the assignment I got. I wrote the code but haven't trouble looping to the scenario it asks for.
Here is the assignment:
Assignment: (Calculating Total Sales) A bakery sells five different products whose retail prices are:
product 1 — $2.47, product 2—$4.42, product 3—$9.98, product 4—$4.49 and product 5— $6.87.
Write a program that reads a series of pairs of numbers as follows:
a) product number
b) quantity sold
1. Your program should use a switch statement to determine the retail price for each product.
2. Your program should calculate and display the total retail value of all products sold.
3. Use a loop to determine when the program should stop looping and display the final results. When product number is - 1, your loop should stop and print the final results.
Having trouble at 3 where user inputs -1 and it would calculate total amount. I tried do while but no luck. Would really appreciate help, I looked at resources and tried but had no luck so hoping for help.
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
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double product1 = 2.47, product2 = 4.40, product3 = 9.98, product4 = 4.49, product5 = 6.87;
double productcount = 0, total1 = 0, total2 = 0, total3 = 0, total4 = 0, total5 = 0;
int productnum = 0;
//for (; productnum != -1;)
//{
cout << "What product number did you sell this week?" << endl;
cin >> productnum;
cout << "Quantity Sold?" << endl;
cin >> productcount;
switch (productnum)
{
case 1:
total1 = (product1 * productcount);
break;
case 2:
total2 = (product1 * productcount);
break;
case 3:
total3 = (product1 * productcount);
break;
case 4:
total4 = (product1 * productcount);
break;
case 5:
total5 = (product1 * productcount);
break;
}
//}
cout << "The total value of all products sold is: $ " << (total1 + total2 + total3 + total4 + total5) << endl;
system("pause");
}
|