Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Copyright Dillon Janakus 2017
- //This code displays the monthly bill
- //for certain service provider packages
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- int main()
- {
- //Declare variables
- int choice= 0; //Choice of the operator
- double minutes= 0; //Minutes used
- double addMinutes= 0; //Additional minutes used
- const int PACKMIN1= 450; //Minutes in package 1
- const int PACKMIN2= 900; //Minutes in package 2
- const float PRICE1= 39.99; //Price of package 1
- const float PRICE2= 59.99; //Price of package 2
- const float PRICE3= 69.99; //Price of package 3
- const float ADD1= 0.45; //Additional minute price of package 1
- const float ADD2= 0.40; //Additional minute price of package 2
- const int PACK_1= 1; //Package A
- const int PACK_2= 2; //Package B
- const int PACK_3= 3; //Package C
- double monthlyBill= 0; //Cost of monthly build
- double savings= 0; //Amount of savings with different package
- cout<< "Package 1: For $39.99 per month 450 minutes "
- "are provided. Additional minutes are $0.45 per minute."<<endl;
- cout<<endl;
- cout<< "Package 2: For $59.99 per month 900 minutes "
- "are provided. Additional minutes are $0.40 per minute."<<endl;
- cout<<endl;
- cout<< "Package 3: For $69.99 per month unlimited "
- "minutes provided." <<endl;
- cout<<endl;
- cout<< "Which package have you purchased? (1, 2, or 3)" <<endl;
- cin>>(choice);
- cout<<endl;
- while(choice<1 || choice>3) //Used to loop code upon invalid entry
- {
- cout<< "That is an invalid package choice, please try again."<<endl;
- cin>>(choice);
- cout<<endl;
- }
- cout<<fixed<<setprecision(2);
- switch(choice)
- {
- case PACK_3:
- cout<< "Your total is $"<<PRICE3<<"."<<endl; //Package is always same price
- return 0;
- {
- case PACK_1:
- cout<< "Enter your amount of minutes used."<<endl;
- cin>>(minutes);
- cout<<endl;
- while(minutes<0)
- {
- cout<< "Invalid number of minutes, please try again."<<endl;
- cin>>(minutes);
- cout<<endl;
- }
- if(minutes>=0 && minutes<=450)
- {
- cout<< "Your bill is $"<<PRICE1<<"."<<endl;
- }
- if(minutes>450)
- {
- addMinutes=(minutes-PACKMIN1); //Calculating the price for extra minutes
- monthlyBill=((addMinutes*ADD1)+PRICE1);
- cout<< "Your total cost is $"<<monthlyBill<<"."<<endl;
- }
- if(monthlyBill>PRICE3)
- {
- savings=(monthlyBill-PRICE3);
- cout<<endl;
- cout<< "You would save $"<<savings<<" if you had package 3."<<endl;
- }
- else if(monthlyBill>PRICE2)
- {
- savings=(monthlyBill-PRICE2);
- cout<<endl;
- cout<< "You would save $"<<savings<<" if you had package 2."<<endl;
- }
- return 0;
- }
- case PACK_2:
- cout<< "Enter your amount of minutes used."<<endl;
- cin>>(minutes);
- cout<<endl;
- while(minutes<0)
- {
- cout<< "Invalid number of minutes, please try again."<<endl;
- cin>>(minutes);
- cout<<endl;
- }
- if(minutes>=0 && minutes<=900)
- {
- cout<< "Your bill is $"<<PRICE2<<"."<<endl;
- }
- else if(minutes>900)
- {
- addMinutes=(minutes-PACKMIN2);
- monthlyBill=((addMinutes*ADD2)+PRICE2);
- cout<< "Your total cost is $"<<monthlyBill<<"."<<endl;
- }
- if(monthlyBill>PRICE3)
- {
- savings=(monthlyBill-PRICE3);
- cout<<endl;
- cout<< "You would save $"<<savings<<" if you had package 3."<<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement