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

2. A mail order house sells five different products whose retail prices are: pro

ID: 3673341 • Letter: 2

Question

2. A mail order house sells five different products whose retail prices are: product 1: $2.98 product 2: $4.50 product 3: $9.98 product 4: $4.49 product 5: $6.87. Write a program that reads a series of pairs of numbers as follows: a) product number 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 retail value of all products sold. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results. ( in C++)

Explanation / Answer

Please find the required program below :

// Example program
#include <iostream>
#include <string>

using namespace std;


float getPrice(int n){

float p;
switch(n) {
  
case 1 : p=2.98; break;
case 2 : p=4.50; break;
case 3 : p=9.98; break;
case 4 : p=4.49; break;
case 5 : p=6.87; break;

}

return p;
  
}
int main()
{

int pn, qn,c;
float total = 0;

cout << "Enter the product number and quantity " << endl;
cin >> pn;
cin >> qn;

total = total + (getPrice(pn) * qn);

cout << "Enter 1 to add more, 0 to display total value and exit" <<endl;
cin >> c;

while(c!=0){

cout << "Enter the product number and quantity " << endl;
cin >> pn;
cin >> qn;

total = total + (getPrice(pn) * qn);

cout << "Enter 1 to add more, 0 to display total value and exit" << endl;
cin >> c;
}

cout << "Total value = " << total <<endl;
}