A mail order house sells five different products whose retail prices are: produc
ID: 3674459 • 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.
I need this program to work in visual studio 2013 c++
Explanation / Answer
//pre-processor
#include<iostream>
#include<stdlib.h>
using namespace std ;
//the main function
int main() {
int product, quantity;
float total=0,price;
cout<<"Enter productNumber and quantity sold (-1 to stop): ";
cin>>product;
if(product==-1)
return 0;
cin>>quantity;
while(true){
switch(product){
case 1:
price = 2.98;
break;
case 2:
price = 4.50;
break;
case 3:
price = 9.98;
break;
case 4:
price = 4.49;
break;
case 5:
price = 6.87;
break;
default:
cout<<"invalid product number"<<endl;;
price = 0;
}
// cout<<"prod: "<<product<<" Q: "<<quantity<<endl;
total = total + (price*quantity);
cout<<"Enter productNumber and quantity sold (-1 to stop): ";
cin>>product;
if(product==-1)
break;
cin>>quantity;
}
cout<<"Tital price: "<<total<<endl;
return 0 ;
}
/*
Output:
Enter productNumber and quantity sold (-1 to stop): 1 2
Enter productNumber and quantity sold (-1 to stop): 2 1
Enter productNumber and quantity sold (-1 to stop): 4 5
Enter productNumber and quantity sold (-1 to stop): -1
Tital price: 32.91
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.