fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int choice;
  7. double hours;
  8.  
  9. cout << "Which Subscription package have you purchased? 1, 2, or 3? " << endl;
  10. cin >> choice;
  11.  
  12. switch (choice)
  13. {
  14. case 1:
  15. cout << "How many hours were used this month? " << endl; //Package A
  16. cin >> hours;
  17. do{
  18. cout << "Please enter a valid number of hours used. " << endl;
  19. cin >> hours;
  20. } while (hours < 0 || hours > 744);
  21.  
  22. double monthlyBill; //Calculated as base price + additional hours
  23.  
  24. if (hours >= 11 || hours <= 744)
  25. monthlyBill = 9.95 + (hours * 2.00);
  26. else
  27. monthlyBill = 9.95;
  28.  
  29. cout << "Your monthly bill is : $";
  30. cout << monthlyBill << endl;
  31. break;
  32.  
  33. case 2: //Package B
  34. cout << "How many hours were used this month?" << endl;
  35. cin >> hours;
  36. while (hours < 0 || hours > 744); //Input validation
  37. {
  38. cout << "Please enter a valid number of hours used. " << endl;
  39. cin >> hours;
  40. }
  41.  
  42. double monthlyBill_b; //Calculated as base price + additional hours
  43.  
  44. if (hours >= 21 || hours <= 744)
  45. monthlyBill_b = 14.95 + (hours * 1.00);
  46. else
  47. monthlyBill_b = 14.95;
  48.  
  49. cout << "Your monthly bill is: $ ";
  50. cout << monthlyBill_b << endl;
  51. break;
  52.  
  53. case 3: //Package C is a flat rate of $19.95 per month
  54. cout << "Your monthly bill is $19.95";
  55. break;
  56. default: cout << "You did not enter 1, 2, or 3. ";
  57. break;
  58. }
  59. return 0;
  60. }
Success #stdin #stdout 0s 3232KB
stdin
1
14
11
stdout
Which Subscription package have you purchased? 1, 2, or 3? 
How many hours were used this month? 
Please enter a valid number of hours used. 
Your monthly bill is : $31.95