(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 // parameterized stream manipulators
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
```

Computer Science & Information Technology

You might also like to view...

The Ruler button is a toggle button

Indicate whether the statement is true or false

Computer Science & Information Technology

Which of the following statements is false?

a. Python applies the operators in arithmetic expressions according to the rules of operator precedence, which are generally the same as those in algebra. b. Parentheses have the highest level of precedence, so expressions in paren-theses evaluate first—thus, parentheses may force the order of evaluation to occur in any sequence you desire. c. In expressions with nested parentheses, such as (a / (b - c)), the expres-sion in the innermost parentheses (that is, b - c) evaluates first. d. If an expression contains several exponentiation operations, Python applies them from left to right.

Computer Science & Information Technology