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

need in c++ with output exercise 5.17 Exercises 207 program reads the number 7,

ID: 3734717 • Letter: N

Question

need in c++ with output exercise 5.17

Exercises 207 program reads the number 7, it should display*Display the b ars of asterisaks afier read all five numbers. 5.17 (Caleulating Sales) An online retailer 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

Answer:

products.cpp:

#include <iostream>

using namespace std;

int main()
{
int productNo; // Product No.
int quantity; // Quantity of Product
char continueFlag; // check to continue loop or not
float totalSold =0; // total values of all products sold
int products[5] = {0};
  
do{ // loop start
//reading values from user
cout<<"Please enter the product no (1-5) : ";
cin>>productNo;
cout<<"Please enter the product no. "<<productNo<<" Quantity : ";
cin>>quantity;
// Switch to identify the type of product
switch(productNo){
  
case 1 :
totalSold = totalSold + (1.29 * quantity);
products[0] = products[0] + quantity;
break;
  
case 2 :
totalSold = totalSold + (4.50 * quantity);
products[1] = products[1] + quantity;
break;
  
case 3 :
totalSold = totalSold + (9.98 * quantity);
products[2] = products[2] + quantity;
break;
  
case 4 :
totalSold = totalSold + (4.49 * quantity);
products[3] = products[3] + quantity;
break;
  
case 5 :
totalSold = totalSold + (6.87 * quantity);
products[4] = products[4] + quantity;
break;
  
}
// ask user to continue or not
cout<<"Do you want to continue Y/N? ";
cin>>continueFlag;
}while( continueFlag != 'N' && continueFlag != 'n' ); // repeat if user want to continue
  
for(int i=0; i<5; i++ ){
cout<<"Products sold for product No. "<< i+1 <<" are : "<<products[i]<<endl;
}
  
//Display total amount of procuts sold
cout<<"The total retail value of sold products is : $"<<totalSold;
return 0;
}

Output:

Please enter the product no (1-5) : 2

Please enter the product no. 2 Quantity : 10

Do you want to continue Y/N? y

Please enter the product no (1-5) : 3

Please enter the product no. 3 Quantity : 10

Do you want to continue Y/N? n

Products sold for product No. 1 are : 0

Products sold for product No. 2 are : 10

Products sold for product No. 3 are : 10

Products sold for product No. 4 are : 0

Products sold for product No. 5 are : 0

The total retail value of sold products is : $144.8