fork download
  1. //Amari Mosley CSC5 Chapter 4, P.224 #23
  2. //
  3. /**************************************************************
  4. *
  5. * Calculating Internet Bill
  6. * ____________________________________________________________
  7. * This program calculates a customer's monthly bill.
  8. *
  9. * Computation is based on the following formulas:
  10. * Package A: $9.95 + $2.00 per hour over 10 hours
  11. * Package B: $14.95 + $1.00 per hour over 20 hours
  12. * Package C: $19.95 unlimited
  13. * ____________________________________________________________
  14. * INPUT
  15. * package : Subscription package letter (A, B, or C)
  16. * hours : Number of access hours used in a month
  17. *
  18. * OUTPUT
  19. * bill : Calculated total monthly bill amount
  20. *
  21. **************************************************************/
  22.  
  23. #include <iostream>
  24. #include <iomanip>
  25. using namespace std;
  26.  
  27. // Defining Main Function
  28. int main ( )
  29. {
  30. // Defining Variables
  31. char package; // The Subscription Package selected by user
  32. double hours; // Number of access hours used in a month
  33. double bill; // Calculated total monthly bill amount
  34.  
  35. // Prompting user for package and hours used
  36. cout << "Enter the subscription package (A, B, or C): ";
  37. cin >> package;
  38.  
  39. // Input Validation for Package Selection
  40. if (package != 'A' && package != 'a' &&
  41. package != 'B' && package != 'b' &&
  42. package != 'C' && package != 'c')
  43. {
  44. cout << "Error: Package must be A, B, or C." << endl;
  45. }
  46. else
  47. {
  48. cout << "Enter the number of hours used: ";
  49. cin >> hours;
  50.  
  51. // Input Validation for Hours
  52. if (hours < 0 || hours > 744)
  53. {
  54. cout << "Error: Hours used cannot be negative or exceed 744." << endl;
  55. }
  56. else
  57. {
  58. // Formatting output for currency
  59. cout << fixed << setprecision(2);
  60.  
  61. // Calculating monthly bill based on package
  62. switch (package)
  63. {
  64. case 'A':
  65. case 'a':
  66. bill = 9.95;
  67. if (hours > 10)
  68. {
  69. bill += (hours - 10) * 2.00;
  70. }
  71. cout << "The total amount due is $" << bill << endl;
  72. break;
  73.  
  74. case 'B':
  75. case 'b':
  76. bill = 14.95;
  77. if (hours > 20)
  78. {
  79. bill += (hours - 20) * 1.00;
  80. }
  81. cout << "The total amount due is $" << bill << endl;
  82. break;
  83.  
  84. case 'C':
  85. case 'c':
  86. bill = 19.95;
  87. cout << "The total amount due is $" << bill << endl;
  88. break;
  89. }
  90. }
  91. }
  92.  
  93. return 0;
  94. }
Success #stdin #stdout 0.01s 5288KB
stdin
A
48
stdout
Enter the subscription package (A, B, or C): Enter the number of hours used: The total amount due is $85.95