A mail order house sells five different products whose retail prices are: produc
ID: 3673675 • Letter: A
Question
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
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-controlled loop to determine when the program should stop looping and display the final results.
Explanation / Answer
#include int main(void){ int type=0; int quantity; double total=0; printf("Enter pairs of item numbers and quantities. "); printf("Enter -1 for the item number to end input. "); while(type!=-1){ scanf("%d %d",&type,&quantity); switch(type){ case 1: total=total+quantity*2.98; break; case 2: total=total+quantity*4.50; break; case 3: total=total+quantity*9.98; break; case 4: total=total+quantity*4.49; break; case 5: total=total+quantity*6.87; break; default: printf("type is wrong:try again "); break; } } printf("Sum of the purchases is :%lf",total); }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.