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. * This program produces a monthly Internet bill. The Internet bill is based on
  10. * a selected subscription package, and the number of hours consumed during the
  11. * billing period.
  12. *
  13. * Computation is based on the Formula:
  14. * Package A : Base fee includes 10 hours, extra hours are charged
  15. * Package B : Base fee includes 20 hours, extra hours are charged
  16. * Package C : Flat rate with unlimited access (no extra charges)
  17. *______________________________________________________________________________
  18. * INPUT
  19. * Package type
  20. * Base fee
  21. * Flat rate
  22. * Package hours
  23. * Hours used
  24. * Base fee
  25. * Extra hours
  26. *
  27. * OUTPUT
  28. * Total monthly bill
  29. *******************************************************************************/
  30. #include <iostream>
  31. #include <iomanip>
  32. using namespace std;
  33.  
  34. // total = ComputePackagePrice(package, hours);
  35. float ComputePackagePrice(char package, float hours);
  36.  
  37. int main() {
  38. char package;
  39. float hours;
  40. float total;
  41.  
  42.  
  43. // Ask for package
  44. cout << "Enter your package (A, B, or C): \n";
  45. cin >> package;
  46.  
  47. // Validate Package
  48. while (package != 'A' && package != 'B' && package != 'C' &&
  49. package != 'a' && package != 'b' && package != 'c') {
  50. cout << "Invalid package. Enter A, B, or C: \n";
  51. cout << "Invalid package. Cannot calculate bill." << endl;
  52. cout << "Enter your package (A, B, or C): \n";
  53. cin >> package;
  54. }
  55. cout << "Line #52: " << package << endl;
  56.  
  57. // Ask for hours
  58. cout << "Enter number of hours used: \n";
  59. cin >> hours;
  60.  
  61. // Only accept valid hours
  62. while (hours < 0 || hours > 744) {
  63. cout << "Invalid hours. Enter a value between 0 and 744: \n";
  64. cin >> hours;
  65. }
  66. cout << "Line #63: " << hours << endl;
  67. // total = ComputePackagePrice(package, hours);
  68. // Calculate total bill based on package
  69. switch (package) {
  70. case 'A': case 'a':
  71. total = 9.95;
  72. if (hours > 10)
  73. total += (hours - 10) * 2.00;
  74. break;
  75. case 'B': case 'b':
  76. total = 14.95;
  77. if (hours > 20)
  78. total += (hours - 20) * 1.00;
  79. break;
  80. case 'C': case 'c':
  81. total = 19.95; // unlimited
  82. break;
  83. }
  84.  
  85. // Display total
  86. cout << fixed << setprecision(2);
  87. cout << "Total amount due: $" << total << endl;
  88.  
  89. return 0;
  90. }
  91. float ComputePackagePrice(char package, float hours)
  92. {
  93.  
  94. }
Success #stdin #stdout 0s 5320KB
stdin
P
3
!
z
B
800
-3
-99
1000
450
stdout
Enter your package (A, B, or C): 
Invalid package. Enter A, B, or C: 
Invalid package. Cannot calculate bill.
Enter your package (A, B, or C): 
Invalid package. Enter A, B, or C: 
Invalid package. Cannot calculate bill.
Enter your package (A, B, or C): 
Invalid package. Enter A, B, or C: 
Invalid package. Cannot calculate bill.
Enter your package (A, B, or C): 
Invalid package. Enter A, B, or C: 
Invalid package. Cannot calculate bill.
Enter your package (A, B, or C): 
Line #52: B
Enter number of hours used: 
Invalid hours. Enter a value between 0 and 744: 
Invalid hours. Enter a value between 0 and 744: 
Invalid hours. Enter a value between 0 and 744: 
Invalid hours. Enter a value between 0 and 744: 
Line #63: 450
Total amount due: $444.95