Programming assignment 2) We are managing a small retail store that sells 4 prod
ID: 3668947 • Letter: P
Question
Programming assignment 2) We are managing a small retail store that sells 4 products: Retail price 2.99 1.99 9.99 4.49 Item number 4 Write a program that takes a pair of numbers as follows «item number> Your program should calculate and display the total retail value of the products sold. Your program should use a switch statement to help determine the price of each product 3) Your program should adhere to the following L/O specification "Enter the item number and quantity sold:" Read a pair of numbers The total retail value for xx units of item yy is: Szz.n" 4) When printing floating point valucs, only print the first 2 decimal places. 5) Example: eigurrola@eigurrola:-/Documents/ee2372 spring2016/solutions/assignment2s Isolution Enter the item number and quantity sold: 3 1 The total retail value for 15 units of iten 3 is: $149.85 eigurrola eigurrola /Documents/ee2372 spring2016/solutions/assignment2SIsolution Enter the item number and quantity sold: 2 5 The total retail value for 5 units of item 2 is:$9.95 eigurrola@eigurrola: /Documents/ee2372 spring2016/solutions/assignment25/solution Enter the item number and quantity sold: 5 2 Item not found eigurrola@eigurrola: /Documents/ee2372 spring2016/solutions/assignment2s 52016/solution s'assignment2solutionExplanation / Answer
#include<stdio.h>
int main(){
int total_quantity;
int item_number;
float total_retail = 0;
// reading item number and quantity in pair from user
printf("Enter the item number and quantity sold: ");
scanf("%d",&item_number);
scanf("%d",&total_quantity);
// switch case based on item number
switch(item_number){
case 1:
total_retail = total_quantity*2.99; // calculating total retail value
break;
case 2:
total_retail = total_quantity*1.99;
break;
case 3:
total_retail = total_quantity*9.99;
break;
case 4:
total_retail = total_quantity*4.49;
break;
default:
printf("Invalid item number "); // if item number is invalid
}
printf("The total retail value for %d units of item %d is: %0.2lf ",total_quantity,item_number,total_retail);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.