//Amari Mosley CSC5 Chapter 4, P.224 #23
//
/**************************************************************
*
* Calculating Internet Bill
* ____________________________________________________________
* This program calculates a customer's monthly bill.
*
* Computation is based on the following formulas:
* Package A: $9.95 + $2.00 per hour over 10 hours
* Package B: $14.95 + $1.00 per hour over 20 hours
* Package C: $19.95 unlimited
* ____________________________________________________________
* INPUT
* package : Subscription package letter (A, B, or C)
* hours : Number of access hours used in a month
*
* OUTPUT
* bill : Calculated total monthly bill amount
*
**************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
// Defining Main Function
int main ( )
{
// Defining Variables
char package; // The Subscription Package selected by user
double hours; // Number of access hours used in a month
double bill; // Calculated total monthly bill amount
// Prompting user for package and hours used
cout << "Enter the subscription package (A, B, or C): ";
cin >> package;
// Input Validation for Package Selection
if (package != 'A' && package != 'a' &&
package != 'B' && package != 'b' &&
package != 'C' && package != 'c')
{
cout << "Error: Package must be A, B, or C." << endl;
}
else
{
cout << "Enter the number of hours used: ";
cin >> hours;
// Input Validation for Hours
if (hours < 0 || hours > 744)
{
cout << "Error: Hours used cannot be negative or exceed 744." << endl;
}
else
{
// Formatting output for currency
cout << fixed << setprecision(2);
// Calculating monthly bill based on package
switch (package)
{
case 'A':
case 'a':
bill = 9.95;
if (hours > 10)
{
bill += (hours - 10) * 2.00;
}
cout << "The total amount due is $" << bill << endl;
break;
case 'B':
case 'b':
bill = 14.95;
if (hours > 20)
{
bill += (hours - 20) * 1.00;
}
cout << "The total amount due is $" << bill << endl;
break;
case 'C':
case 'c':
bill = 19.95;
cout << "The total amount due is $" << bill << endl;
break;
}
}
}
return 0;
}