Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A mail order house sells five different products whose retail prices are: produc

ID: 3624446 • Letter: A

Question

A mail order house sells five different products whose retail prices are:
product 1 : $5, product 2 : $ 10, product 3 : $ 15, product 4 : $20
product 5 : $25
Write a program that reads a series of pairs of numbers as follows:
a - product no.
b- quantity sold
Your program should use a switch statement to determine the retail price for each product. Your program should calculate and display the total value of all products sold. Use a sentinel controlled loop to determine when program should stop looping and display final results.

Explanation / Answer

#include <iostream>

#include <iomanip>
using namespace std;


int main()
{
int product, quantity;
double total = 0.0;

cout << "Enter pairs of item numbers and quantities."
<< " Enter -1 for the item number to end input: ";
cin >> product;

while ( product != -1 ) {
cin >> quantity;
switch ( product ) {
case 1:
total += quantity * 5;
break;
case 2:
total += quantity * 10;
break;
case 3:
total += quantity * 15;
break;
case 4:
total += quantity * 20;
break;
case 5:
total += quantity * 25;
break;
default:
cout << "Invalid product code: " << product
<< " Quantity: " << quantity << ' ';
break;
}

cout << "Enter pairs of item numbers and quantities. "
<< "Enter -1 for the item number to end input: ";
cin >> product;
}

cout << setiosflags( ios::fixed | ios::showpoint )
<< "The total retail value was: " << setprecision( 2 )
<< total << endl;

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote