Question

c++ (visual studio) A mail order house sells five different products whose product numbers and retail...

c++ (visual studio)

A mail order house sells five different products whose product numbers and retail prices are:

product 1 - $2.98, product 2 - $4.50, product 3 - $9.98, product 4 - $4.49, product 5 - $6.87.

  1. Write a program that reads a series of pairs of numbers (from user). That is, each time it reads the pairs of values as follows:

i) product number

ii) quantity of that product sold

  1. Your program should use a switch statement to determine the retail price for each product.
  2. Your program should calculate and display the total retail value of all products sold.
  3. Use a sentinel-controlled while loop so user can indicate when the program should stop looping and display the final results.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

NOTE:
########

Input to the program is product id and price which is seprated by a space. To end the program enter ctlr+D which is EOF

//######################## PGM START ##############################

#include<iostream>
using namespace std;

int main(){
   double product[5]={0};
   int id;
   double qty=0.0,total=0.0;
   //request id and quqntity of product from users
   cout<<"Enter product id and quantity (ctrl+D to exit): ";
   //read id and quantity untill user enter EOF(ie ctrl+d)
   while(cin>>id>>qty){
       switch(id){
           case 1: product[0]+=(qty*2.98);
                   break;
                  
           case 2: product[1]+=(qty*4.50);
                   break;
                  
           case 3: product[2]+=(qty*9.98);
                   break;
                  
           case 4: product[3]+=(qty*4.49);
                   break;
                  
           case 5: product[4]+=(qty*6.87);
                   break;
                  
           default: cout<<"Wrong product id!!!!\n";
                   break;
       }
   }
   //print each product retail price
   for(int i=0;i<5;i++){
       cout<<"Product "<<(i+1)<<": $"<<product[i]<<"\n";
       //finding the total retail price
       total+=product[i];
   }
   //printin the total retail price
   cout<<"\n\tTotal retail price: $"<<total<<"\n";
  
   return 0;
}

//###################### PGM END #######################################

OUTPUT
#########

Add a comment
Know the answer?
Add Answer to:
c++ (visual studio) A mail order house sells five different products whose product numbers and retail...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT