//Diego Martinez CSC5 Chapter 4, P.226,#24
/*******************************************************************************
* Determining Best Internet Package
* ______________________________________________________________________________
* This program calculates a customer's monthly Internet bill based on the subsc-
* ription package they selected and the number of hours they used during the
* month. This program also determines whether the customer could save money by
* switching to a different package.
*
* Computation is based on the Formula:
* Package A: Base fee includes 10 hours, extra hours are charged
* Package B: Base fee includes 20 hours, extra hours are charged
* Package C: Flat rate with unlimited access (no extra charges)
*______________________________________________________________________________
* INPUT
* Package Type
* Hours used
*
* OUTPUT
* Total monthly bill
* Any potential savings from switching packages (if applicable)
*******************************************************************************/
#include <iostream>
#include <cctype>
using namespace std;
// Function to calculate bill based on package and hours
double calculateBill(char package, int hours) {
double bill = 0.0;
switch (package) {
case 'A':
bill = 9.95;
if (hours > 10)
bill += (hours - 10) * 2.0;
break;
case 'B':
bill = 14.95;
if (hours > 20)
bill += (hours - 20) * 1.0;
break;
case 'C':
bill = 19.95;
break;
}
return bill;
}
int main() {
char package;
int hours;
// Input package
cout << "Enter your package (A, B, or C): ";
cin >> package;
package = toupper(package);
// Validate package
if (package != 'A' && package != 'B' && package != 'C') {
cout << "Invalid package selection.\n";
return 1;
}
// Input hours
cout << "Enter number of hours used: ";
cin >> hours;
// Validate hours
if (hours < 0 || hours > 744) {
cout << "Invalid number of hours. Must be between 0 and 744.\n";
return 1;
}
// Calculate current bill
double currentBill = calculateBill(package, hours);
// Output current bill
cout << "Your total monthly bill: $" << currentBill << endl;
// Calculate and display savings
if (package == 'A') {
double costB = calculateBill('B', hours);
double costC = calculateBill('C', hours);
if (costB < currentBill) {
cout << "You would save $" << currentBill - costC
<< " by switching to Package C.\n";
}
}
else if (package == 'B') {
double costC = calculateBill('C', hours);
if (costC < currentBill) {
cout << "You would save $" << currentBill - costC
<< " by switching to Package C.\n";
}
}
return 0;
}