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 sample output: Enter product number (1-5) (0 to stop): 1 Enter quantity sold: 5 Enter product number (1-5) (0 to stop): 5 Enter quantity sold: 10 Enter product number (1-5) (0 to stop): 0 Product 1: $14.90 Product 2: $0.00 Product 3: $0.00 Product 4: $0.00 Product 5: $68.70
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
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
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
sample output:
Enter product number (1-5) (0 to stop): 1
Enter quantity sold: 5
Enter product number (1-5) (0 to stop): 5
Enter quantity sold: 10
Enter product number (1-5) (0 to stop): 0
Product 1: $14.90
Product 2: $0.00
Product 3: $0.00
Product 4: $0.00
Product 5: $68.70
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images