380,753 views
1 vote
1 vote
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.

User Cork Kochi
by
3.0k points

1 Answer

22 votes
22 votes

Answer:

#include <stdio.h>

int main()

{

float list[5]={2.98,4.50,9.98,4.49,6.87 };

int producttype=0;

int qty;

double total=0;

printf("Below is the List of Products with Price\\");

for(int i=0;i<5;i++)

{

printf("Product%d Price is %.2f\\",i+1,list[i]);

}

printf("\\Enter pairs of Product Numbers and Its Quantities.\\");

printf("Enter -1 for the Product Number to end input.\\");

while(true){

scanf("%d",&producttype);

if(producttype == -1)

{

break;

}

scanf("%d",&qty);

switch(producttype){

case 1:

total=total+qty*2.98;

break;

case 2:

total=total+qty*4.50;

break;

case 3:

total=total+qty*9.98;

break;

case 4:

total=total+qty*4.49;

break;

case 5:

total=total+qty*6.87;

break;

default:

printf("Wrong Product Id\\");

break;

}

}

printf("Sum of the purchases is :%.2f\\",total);

}

Output:-

An online retailer sells five products whose retail prices are as follows: product-example-1
User Keanna
by
3.5k points