program instantly closing

ive been trying to get the program to calculate package A with 30 hours but it instantly closes without calculating. not sure what i did wrong

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
132
133
134
135
136
137
138
139
//An Internet service provider has three different subscription packages for its customers:
//Package A: For $9.95 per month 10 hours of access are provided. Additional hours
//are $2.00 per hour.
//Package B: For $14.95 per month 20 hours of access are provided. Additional
//hours are $1.00 per hour.
//Package C: For $19.95 per month unlimited access is provided.

//Write a program that calculates a customer's monthly bill. It should ask which package
//the customer has purchased and how many hours were used. It should then display
//the total amount due.
//Input Validation: Be sure the user only selects package A, B, or C. Also, the number
//of hours used in a month cannot exceed 744.

//Modify the Program in Programming Challenge 23 so that it also displays how much
//money Package A customers would save if they purchased packages B or C, and how
//much money Package B customers would save if they purchased Package C. If there
//would be no savings, no message should be printed.

//Months with 30 days have 720 hours, and months with 31 days have 744 hours. February,
//with 28 days, has 672 hours. Enhance the input validation of the Internet Service
//Provider program by asking the user for the month (by name), and validating that
//the number of hours entered is not more than the maximum for the entire month.
//Here is a table of the months, their days, and number of hours in each.

#include <iostream>
#include <string>

using namespace std;
//prototypes
double total(int type, int hours);

int main()
{
    
    cout << "Which package did you purchase?: A, B, or C?\n\n"
    "A - $9.95 per month with 10 hours allowed. More hours are $2.00 per hour.\n"
    "B - $14.95 per month with 20 hours allowed. More hours are $1.00 per hour.\n"
    "C - $19.95 per month with infinite hours allowed.\n\n";
    char package;
    cin >> package;
    while (package != 'A' && package != 'a' && package != 'B' && package != 'b' && package != 'C' && package != 'c')
    {
    cout << "Invalid selection. Please only enter the letter A, B or C.";     
    cout << "Enter your package type A, B or C: ";
    cin >> package;
}
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    switch (package)
    {
           //Package A: For $9.95 per month 10 hours of access are provided. Additional hours
//are $2.00 per hour.
    case 'A':
    case 'a': 
         int packagetype;
         packagetype = 1;
         cout << "\nyou picked A.\n\nHow many hours were you on the internet?:\n\n";
    int nethours;
    cin >> nethours;
  
     while (nethours > 744)
     {
     cout << "\nThat is impossible.";
     cout << "How many hours were you on the internet?:\n\n";
     cin >> nethours;
     }     
    break;
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //Package B: For $14.95 per month 20 hours of access are provided. Additional
//hours are $1.00 per hour.
    case 'B':
    case 'b': cout << "\nYou picked B.\n\nHow many hours were you on the internet?:\n\n";
    
    cin >> nethours;
    {
   if (nethours <= 20)
{
    cout << "Your bill is 14.95.";
}
    else if (nethours > 20)
    {
         while (nethours > 744)
         {
         cout << "That is impossible. Re-enter your hours.:";
         cin >> nethours;
         }
         //need calculation
          }
          break;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Package C: For $19.95 per month unlimited access is provided.
    case 'C':
    case 'c': cout << "\nYou picked C.\nHow many hours were you using internet?:\n";
    
    cin >> nethours;
    //
     while (nethours > 744)
    {
          cout << "That is impossible. Please re-enter your internet hours.\n";
    cin >> nethours;
}
    //
    if (nethours <= 744)
    {
    cout << "Your bill is $19.95.\n";
}
     
    break;
    default: cout << "Not a valid answer.\n";
    }
    total(packagetype, nethours);
cin.get ();
return 0;
}
}
//price calculator~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double total(int type, int hours)
{
      if (type == 1)
      {
               if (hours <= 10)
    {
                   
      cout << "\nyou have a bill of 9.95 in your account because you did not go over the limit.\n";
    }
else if (hours > 10)
  {
        cout << "\nYou have a bill of " << (hours - 10.00) * 1.00 + 9.95  << " in your account because of extra fees.\n\nYou could have saved " 
     << ((hours - 20) * 2.00 + 14.95) - ((hours - 10.00) * 1.00 + 9.95) << " dollars if you had package B.\n";
     }
else 
{
     cout << "invalid answer to A";
     }
cout << "Press enter to continue.";
cin.get();
cin.get();
}
}
Last edited on
I don't see anywhere in your code that you used your function.
closed account (EwCjE3v7)
ANSWER

Put this in function

system("PAUSE");

This should work.
Last edited on
edited thanks for pointing that out. code is now in use.
closed account (EwCjE3v7)
No problem.
If you need help just check back on site and there will always be someone that can help.
Edit
Can you press the solved button on very top.thanks
Last edited on
Topic archived. No new replies allowed.