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

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139`` ``````//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 #include 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)

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.