1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
// Purpose: Ask which package the customer has purchased and how many hours were
// used for the billing cycle. It should then display the total amount
// due based on input validation. Input Validaton: be sure the user
// onlys select package a,b,or c. The number of usage hours cannot
// exceed 744. Program should display saving for switching a cheaping
// package to a more expensive package.
// *****************************************************************************
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
int main()
{
// Declare Constants
const int MAXIMUM_HOURS = 744;
const double PACKAGE_A = 9.95,
PACKAGE_A_HOURS = 10,
OVER_PACKAGE_A =2.00,
PACKAGE_B = 14.95,
PACKAGE_B_HOURS = 20,
OVER_PACKAGE_B =1.00,
PACKAGE_C = 19.95;
// Declare Variables
char customerPackage;
double hoursUsed =0,
overTime =0,
amountDue =0,
packageBDifference =0,
bSaveHours = 0,
packageCDifference =0,
cSaveHours = 0,
excessCharged = 0;
// prompts the user to enter the customer's package and reads the input
cout << "Please enter the customer's package: ";
cin >> customerPackage;
// validates the input
if (customerPackage !='a' && customerPackage !='A' &&
customerPackage !='b' && customerPackage !='B' &&
customerPackage !='c' && customerPackage !='C')
{
cout << "\nError. package does not exist\n"
<< "Please enter the customer's purchased package plan: ";
cin >> customerPackage;
}
// prompts user to enter the hours used for the current billing cycle and
// reads the input
cout << "Please the number of hours used for the current cycle: ";
cin >> hoursUsed;
// validates the input
if (hoursUsed >= MAXIMUM_HOURS || hoursUsed < 0)
{
cout << "\nError. hours are outside of maximum range\n"
<< "Please enter the current month's hours usage: ";
cin >> hoursUsed;
}
// computes the amount due based on package type and hours usage
if ((customerPackage == 'a' || customerPackage == 'A')
&& hoursUsed <= PACKAGE_A_HOURS)
{
amountDue = PACKAGE_A;
}
else if((customerPackage == 'a' || customerPackage == 'A')
&& hoursUsed > PACKAGE_A_HOURS)
{
overTime = hoursUsed -PACKAGE_A_HOURS;
excessCharged = overTime * OVER_PACKAGE_A;
amountDue = PACKAGE_A + excessCharged;
}
else if ((customerPackage == 'b' || customerPackage == 'B')
&& hoursUsed <= PACKAGE_B_HOURS)
{
amountDue = PACKAGE_B;
}
else if((customerPackage == 'b' || customerPackage == 'B')
&& hoursUsed > PACKAGE_B_HOURS)
{
overTime = hoursUsed -PACKAGE_B_HOURS;
excessCharged = overTime * OVER_PACKAGE_B;
amountDue = PACKAGE_B + excessCharged;
}
else
{
amountDue = PACKAGE_C;
}
// computes the available savings for different package types THIS IS WHERE IT GOES WRONG
if ((hoursUsed < PACKAGE_A_HOURS && customerPackage =='a' ||
customerPackage =='A'))
{
packageBDifference = PACKAGE_B - PACKAGE_A;
bSaveHours = packageBDifference / PACKAGE_A_HOURS;
packageCDifference = PACKAGE_C - PACKAGE_B_HOURS;
cSaveHours = PACKAGE_C / PACKAGE_B_HOURS;
}
else if ((customerPackage == 'b' ||customerPackage == 'B')
&& hoursUsed < PACKAGE_B)
{
packageCDifference = PACKAGE_C - PACKAGE_B_HOURS;
cSaveHours = PACKAGE_C / PACKAGE_B_HOURS;
}
//outputs to the display and the amount charged and savings
cout << fixed << showpoint <<setprecision(2);
cout << "\nCustomer is charged " << amountDue << endl;
if ( bSaveHours < 0)
{
cout << "With the B package customer can save: " << bSaveHours << endl;
cout << "With the C package customer can save: " << cSaveHours << endl;
}
else
system("pause");
return 0;
}
|