Phone provider program help please

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;

string name;
char package;
double hours;
double total;

cout << "Customer name: ";
getline(cin, name);
cout << "Phone package selection menu.\n\n";
cout << "A. Package A\n";
cout << "B. Package B\n";
cout << "C. Package C\n";
cout << "D. Terminate the program\n\n";
cin >> package;

//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";
}

return 0;
}



Last edited on
can you use code tags please?

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
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

#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;

  string name;
  char package;
  double hours;
  double total;

  cout << "Customer name: ";
  getline(cin, name);
  cout << "Phone package selection menu.\n\n";
  cout << "A. Package A\n";
  cout << "B. Package B\n";
  cout << "C. Package C\n";
  cout << "D. Terminate the program\n\n";
  cin >> package;

   //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;

     }

    cout << "Your total is $" << total << endl;

    if (package < 'A' || package > 'C') {
    cout << "Valid choices are A-D.\n";
    cout << "Run the program again and select A-D.\n";
  }
  return 0;
}




 
Last edited on
sorry about that didn't know what code tags were
closed account (48T7M4Gy)
You might misunderstand that you need to program a switch. Why not start by just presenting the costs for all the plans?
Last edited on
no worries.

you didnt seem to read the 2nd part of my post :)

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.
Topic archived. No new replies allowed.