fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 4 P. 226 #23
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Compute Subscription Payment
  6.  * ____________________________________________________________________________
  7.  * This program will prompt users to select a package they used, enter the
  8.  * hours it was used for and then it calculates the total monthly bill based
  9.  * on the package
  10.  *
  11.  * Formulas that will be used:
  12.  * total += (hours - 10) * 2.00
  13.  * total += (hours - 20) * 1.00
  14.  *_____________________________________________________________________________
  15.  * INPUT
  16.  * package //users choice of package used
  17.  * hours //users amount of hours used
  18.  *
  19.  * OUTPUT
  20.  * total //total based of package used and hours used
  21.  *****************************************************************************/
  22. #include <iostream>
  23. #include <iomanip>
  24. using namespace std;
  25. int main()
  26. {
  27. char package; //INPUT - user's choice of package
  28. float hours; //INPUT - user's amount of hours used
  29. float total; //OUTPUT - user's total amount to pay
  30. //
  31. //Prompt user for package
  32. cout << "Enter your subscription package (A, B, or C): " << endl;
  33. cin >> package;
  34. //
  35. //Validate package input
  36. if (package != 'A' && package != 'B' && package != 'C'){
  37. cout << "Invalid package selected. Please choose A, B, or C." << endl;
  38. return 1;
  39. }
  40. //
  41. //Get user's hours used
  42. cout << "Enter the number of hours used (0-744): " << endl;
  43. cin >> hours;
  44. //
  45. //Validate hours input
  46. if (hours < 0 || hours > 744) {
  47. cout << "Invalid number of hours. Please enter a value between 0 and 744" << endl;
  48. return 1;
  49. }
  50. //
  51. //Calculate bill based on package selected
  52. switch (package) {
  53. case 'A':
  54. total = 9.95;
  55. if (hours > 10)
  56. total += (hours - 10) * 2.00;
  57. break;
  58. case 'B':
  59. total = 14.95;
  60. if (hours > 20)
  61. total += (hours - 20) * 1.00;
  62. break;
  63. case 'C':
  64. total = 19.95; //unlimited
  65. break;
  66. }
  67. //
  68. //Display the result
  69. cout << fixed << setprecision (2);
  70. cout << "Total amount due: $" << total << endl;
  71. return 0;
  72. }
Success #stdin #stdout 0s 5316KB
stdin
C
545
stdout
Enter your subscription package (A, B, or C): 
Enter the number of hours used (0-744): 
Total amount due: $19.95