fork download
  1. //Diego Martinez CSC5 Chapter 4, P.226,#23
  2. /*******************************************************************************
  3. * CALCULATE MONTHLY INTERNET BILL
  4. * ______________________________________________________________________________
  5. * This program calculates a customer's monthly Internet bill based on the subsc-
  6. * ription package they selected and the number of hours they used during the
  7. * month.
  8. *
  9. * Computation is based on the Formula:
  10. * Package A : Base fee includes 10 hours, extra hours are charged
  11. * Package B : Base fee includes 20 hours, extra hours are charged
  12. * Package C : Flat rate with unlimited access (no extra charges)
  13. *______________________________________________________________________________
  14. * INPUT
  15. * Package Type
  16. * Hours used
  17. *
  18. * OUTPUT
  19. * Total monthly bill
  20. *******************************************************************************/
  21. #include <iostream>
  22. #include <cctype>
  23. using namespace std;
  24.  
  25. int main() {
  26. char package;
  27. int hours;
  28. double totalBill = 0.0;
  29.  
  30. // Input package
  31. cout << "Enter your package (A, B, C): \n";
  32. cin >> package;
  33. package = toupper(package);
  34.  
  35. // Validate package
  36. if (package != 'A' && package != 'B' && package != 'C'){
  37. cout << "Invalid package selection.\n";
  38. return 1;
  39. }
  40.  
  41. // Input hours used
  42. cout << "Enter number of hours used: \n";
  43. cin >> hours;
  44.  
  45. // Validate hours
  46. if (hours < 0 || hours > 744) {
  47. cout << "Invalid number of hours. Must be between 0 and 744.\n";
  48. return 1;
  49. }
  50.  
  51. // Calculate bill
  52. switch (package) {
  53. case 'A':
  54. totalBill = 9.95;
  55. if (hours > 10)
  56. totalBill += (hours - 10) * 2.0;
  57. break;
  58.  
  59. case 'B':
  60. totalBill = 14.95;
  61. if (hours > 20)
  62. totalBill += (hours - 10) * 1.0;
  63. break;
  64.  
  65. case 'C':
  66. totalBill = 19.95;
  67. break;
  68. }
  69.  
  70. // Output result
  71. cout << "Your total monthly bill is: $" << totalBill << endl;
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0s 5316KB
stdin
A
12
stdout
Enter your package (A, B, C): 
Enter number of hours used: 
Your total monthly bill is: $13.95