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

C++ Use visual studio not java 3) A mail-order house sells five products whose r

ID: 3566194 • Letter: C

Question

C++ Use visual studio not java 3) A mail-order house sells five products whose retail prices are as follows: product 1, $2.98; product 2, $4.50; product 3, $9.98; product 4, $4.49 and product 5, $6.87. Write an application 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. It 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.

Explanation / Answer

#include <iostream>
using namespace std;

int main()
{
   int product, qty;
   float total = 0;
   bool flag = false;

   cout << "Product varies from 1 to 5, and qty should be positive (not even 0).";
   cout << "If any time the conditions are violated the program will exit.";
   Cout << "To exit enter values: 0 0";
  
   while(1)
   {
       cin >> product >> qty;

       if(qty < 1)
           break;

       switch(product){
           case 1:
               total += 2.98*qty;
               break;
           case 2:
               total += 4.5*qty;
               break;
           case 3:
               total += 9.98*qty;
               break;
           case 4:
               total += 4.49*qty;
               break;
           case 5:
               total += 6.87*qty;
               break;
           default:
               flag = true;
       }

       if(flag)
           break;
   }

   cout << "The total retail value of all prodcuts sold is $" << total;
   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