Hey guys i need help on how i can calculate a user savings if he were to switch to a different package than the one chosen at the beginning.
The packages are as follows.
Package A: For $9.95 per month, 5 hours of call time are provided.
Additional usage costs $0.08 per minute.
Package B: For $14.95 per month, 10 hours of call time are provided.
Additional usage costs $0.06 per minute.
Package C: For $19.95 per month, unlimited call time is provide
Here is the source code
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main ()
{
//Constants for phone packages.
const double A = 9.95;
const double B = 14.95;
const double C = 19.95;
const double eA = 0.08;
const double eB = 0.06;
const double pA = 5;
const double pB = 10;
const double hR = 60;
//Validate input from user
if ((package >= 'A') && (package <= 'C')) {
cout << "How many hours did you talk on the phone? ";
cin >> hours;
}
//Calculate users monthly bill based on inputs
switch (package)
{
case 'A': total = A + (hours - pA) * eA * hR;
if (hours <= pA)
total = A;
break;
case 'B': total = B + (hours - pB) * eB * hR;
if (hours <= pB)
total = B;
break;
case 'C': total = C;
if (package < 'A' || package > 'C') {
cout << "Valid choices are A-D.\n";
cout << "Run the program again and select A-D.\n";
}
There's no harm in calculating the amounts for all 3 packages, then asking the user their old package and new package and then doing showing them the difference.
1. ask how many hours user talks on the phone.
2. calculate costs for all 3 packages.
3. ask user what his or her current package is, and what the new one might be.
4. do the difference calculation of these 2 packages and show user.