(Calculating Total Sales) 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 and 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-con- trolled loop to determine when the program should stop looping and display the final results.
What will be an ideal response?
```
// Calculate sales, based on an product number and quantity sold
#include
#include
using namespace std;
int main()
{
double product1 = 0; // amount sold of first product
double product2 = 0; // amount sold of second product
double product3 = 0; // amount sold of third product
double product4 = 0; // amount sold of fourth product
double product5 = 0; // amount sold of fifth product
int productId = 1; // current product id number
int quantity; // quantity of current product sold
// set floating-point number format
cout << fixed << setprecision( 2 );
// ask user for product number until flag value entered
while ( productId != -1 )
{
// determine the product chosen
cout << "Enter product number (1-5) (-1 to stop): ";
cin >> productId;
// verify product id
if ( productId >= 1 && productId <= 5 )
{
// determine the number sold of the item
cout << "Enter quantity sold: ";
cin >> quantity;
// increment the total for the item by the
// price times the quantity sold
switch ( productId )
{
case 1:
product1 += quantity * 2.98;
break;
case 2:
product2 += quantity * 4.50;
break;
case 3:
product3 += quantity * 9.98;
break;
case 4:
product4 += quantity * 4.49;
break;
case 5:
product5 += quantity * 6.87;
break;
} // end switch
} // end if
```
You might also like to view...
You will often find ________ on a web document that, when clicked, act as connectors to another document on the World Wide Web.
A. tags B. hyperlinks C. cookies D. bookmarks
A function can be called multiple times within a block of code.
Answer the following statement true (T) or false (F)
After resizing a text block, the circle handle changes to a square, indicating that the text block now has a fixed width.
Answer the following statement true (T) or false (F)
Given the following list, the first element to be tested using the sequential search and a target of 5 is:{1, 2, 3, 4, 5, 6, 7, 8, 9}
A. 1 B. 2 C. 5 D. 7 E. 9