Tuesday 14 July 2020

13. 5.17 (Calculating Sales) 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.

13. 5.17 (Calculating Sales) 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.

Code:
#include<iostream>
using namespace std;
int main(){
    int number,quantity=0;
    int quantity1=0,quantity2=0,quantity3=0,quantity4=0,quantity5=0;
    double amount1=.0, amount2=.0,amount3=.0,amount4=.0,amount5=.0;
    
 
        cout<<" Enter the Product and quantity sold"<<endl;
        cin>>number;
        cin>>quantity;
      
  
    switch(number){
        case 1:
            quantity1=quantity;
            amount1=quantity*2.98;
            break;
     
    case 2:
        quantity2=quantity;
        amount2=quantity*4.58;
        break;
      
        case 3:
            quantity3=quantity;
            amount3=quantity*9.98;
          
        break;
        case 4:
            quantity4=quantity;
            amount4=quantity*4.49;
          
            case 5:
                quantity5=quantity;
                amount5=quantity*6.87;
                break;
              
                default:
                    cout<<" Enter the correct product number "<<endl;
                  
                    }
                 
                cout<<" Sold prod no "<<quantity1+quantity2+quantity3+quantity4+quantity5<<endl;
                cout<<" Product value "<<amount1+amount2+amount3+amount4+amount5<<endl;
              
                return 0;
          
              
              
  
  
  
}

No comments:

Post a Comment