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

An online retailer sells five products whose retail prices are as follows: Produ

ID: 3639128 • Letter: A

Question

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 number as follows:
a) product number;
b) quantity sold.

Your program should use a "Select...Case" statement to determine the retail price for each product. It should calculate and display the total retail value of all products sold in an output "Label." Keep the total retail value up to date as the user enters values. [Hint: Create instance variables to store the quantity sold of each product so the values are maintained between calls to the event handler.]

Explanation / Answer

Below is a code in Visual Basic (VB):


Module cost

Sub Main()
Dim product As Integer
Dim quantity As Integer
Dim done As String
Dim totalsales As Double

quantity = 0
totalsales = 0
product = 0
done = "y"

Do Until done = "n"
Console.WriteLine("Enter Product Number: ")
product = Console.ReadLine
Console.WriteLine("Enter how many were sold: ")
quantity = Console.ReadLine

Select Case product
Case 1
totalsales += (2.98 * quantity)
Case 2
totalsales += (4.5 * quantity)
Case 3
totalsales += (9.98 * quantity)
Case 4
totalsales += (4.49 * quantity)
Case 5
totalsales += (6.87 * quantity)
End Select

Console.WriteLine("Would you like to enter another sale? (y/n): ")
done = Console.ReadLine
Loop

Console.WriteLine(totalsales)

End Sub

End Module