Advertisement
YTTB

Service Provider B

Nov 6th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.00 KB | None | 0 0
  1. //Copyright Dillon Janakus 2017
  2. //This code displays the monthly bill
  3. //for certain service provider packages
  4.  
  5. #include <iostream>
  6. #include <cmath>
  7. #include <iomanip>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.     //Declare variables
  14.  
  15.     int choice=                 0; //Choice of the operator
  16.     double minutes=             0; //Minutes used
  17.     double addMinutes=          0; //Additional minutes used
  18.     const int PACKMIN1=       450; //Minutes in package 1
  19.     const int PACKMIN2=       900; //Minutes in package 2
  20.     const float PRICE1=     39.99; //Price of package 1
  21.     const float PRICE2=     59.99; //Price of package 2
  22.     const float PRICE3=     69.99; //Price of package 3
  23.     const float ADD1=        0.45; //Additional minute price of package 1
  24.     const float ADD2=        0.40; //Additional minute price of package 2
  25.     const int PACK_1=           1; //Package A
  26.     const int PACK_2=           2; //Package B
  27.     const int PACK_3=           3; //Package C
  28.     double monthlyBill=         0; //Cost of monthly build
  29.     double savings=             0; //Amount of savings with different package
  30.  
  31.     cout<< "Package 1: For $39.99 per month 450 minutes "
  32.            "are provided. Additional minutes are $0.45 per minute."<<endl;
  33.     cout<<endl;
  34.  
  35.     cout<< "Package 2: For $59.99 per month 900 minutes "
  36.            "are provided. Additional minutes are $0.40 per minute."<<endl;
  37.     cout<<endl;
  38.  
  39.     cout<< "Package 3: For $69.99 per month unlimited "
  40.            "minutes provided."                                     <<endl;
  41.     cout<<endl;
  42.  
  43.     cout<< "Which package have you purchased? (1, 2, or 3)" <<endl;
  44.     cin>>(choice);
  45.     cout<<endl;
  46.  
  47.        while(choice<1 || choice>3)  //Used to loop code upon invalid entry
  48.         {
  49.          cout<< "That is an invalid package choice, please try again."<<endl;
  50.          cin>>(choice);
  51.          cout<<endl;
  52.         }
  53.  
  54.  
  55.     cout<<fixed<<setprecision(2);
  56.     switch(choice)
  57. {
  58.     case PACK_3:
  59.     cout<< "Your total is $"<<PRICE3<<"."<<endl;            //Package is always same price
  60.     return 0;
  61.     {
  62.     case PACK_1:
  63.     cout<< "Enter your amount of minutes used."<<endl;
  64.     cin>>(minutes);
  65.     cout<<endl;
  66.  
  67.     while(minutes<0)
  68.         {
  69.          cout<< "Invalid number of minutes, please try again."<<endl;
  70.          cin>>(minutes);
  71.          cout<<endl;
  72.         }
  73.  
  74.     if(minutes>=0 && minutes<=450)
  75.         {
  76.         cout<< "Your bill is $"<<PRICE1<<"."<<endl;
  77.         }
  78.  
  79.         if(minutes>450)
  80.             {
  81.              addMinutes=(minutes-PACKMIN1);                 //Calculating the price for extra minutes
  82.              monthlyBill=((addMinutes*ADD1)+PRICE1);
  83.              cout<< "Your total cost is $"<<monthlyBill<<"."<<endl;
  84.             }
  85.         if(monthlyBill>PRICE3)
  86.         {
  87.           savings=(monthlyBill-PRICE3);
  88.           cout<<endl;
  89.           cout<< "You would save $"<<savings<<" if you had package 3."<<endl;
  90.         }
  91.             else if(monthlyBill>PRICE2)
  92.             {
  93.               savings=(monthlyBill-PRICE2);
  94.               cout<<endl;
  95.               cout<< "You would save $"<<savings<<" if you had package 2."<<endl;
  96.             }
  97.             return 0;
  98.  
  99.     }
  100.     case PACK_2:
  101.     cout<< "Enter your amount of minutes used."<<endl;
  102.     cin>>(minutes);
  103.     cout<<endl;
  104.  
  105.     while(minutes<0)
  106.         {
  107.          cout<< "Invalid number of minutes, please try again."<<endl;
  108.          cin>>(minutes);
  109.          cout<<endl;
  110.         }
  111.  
  112.         if(minutes>=0 && minutes<=900)
  113.         {
  114.         cout<< "Your bill is $"<<PRICE2<<"."<<endl;
  115.         }
  116.         else if(minutes>900)
  117.             {
  118.              addMinutes=(minutes-PACKMIN2);
  119.              monthlyBill=((addMinutes*ADD2)+PRICE2);
  120.              cout<< "Your total cost is $"<<monthlyBill<<"."<<endl;
  121.             }
  122.         if(monthlyBill>PRICE3)
  123.         {
  124.           savings=(monthlyBill-PRICE3);
  125.           cout<<endl;
  126.           cout<< "You would save $"<<savings<<" if you had package 3."<<endl;
  127.         }
  128. }
  129.  
  130.  
  131.     return 0;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement