fork download
  1. //Cameron Pham CS1A Chapter 4, P. 226, #23
  2. //
  3. /******************************************************************************
  4. * Calculate Internet Bill
  5. * ______________________________________________________________________________
  6. * This program accepts a character for the internet plan package and accpets an
  7. * integer value for the amount of hours spent. It calculates the bill.
  8. * ______________________________________________________________________________
  9. * INPUT
  10. * Internet package plan
  11. * Hours of internet spent
  12. * Price of internet package plan
  13. *
  14. * OUTPUT
  15. * Total price of the bill
  16. *******************************************************************************/
  17. #include <iostream>
  18. #include <iomanip>
  19. using namespace std;
  20.  
  21. int main()
  22. {
  23. char package;
  24. double hours;
  25. double bill = 0.0;
  26.  
  27. // Ask the user which package they purchased
  28. cout << "Select your internet plan (A, B, or C).\n";
  29. cin >> package;
  30. cout << "You have internet plan " << package << ".\n";
  31.  
  32. // Validate the package
  33. if (package != 'A' && package != 'B' && package != 'C')
  34. {
  35. cout << "Error: Invalid package. Please select A, B, or C." << endl;
  36. return 0;
  37. }
  38.  
  39. // Ask how many hours were used
  40. cout << "Enter the number of hours used.\n";
  41. cin >> hours;
  42.  
  43. // Validate the number of hours
  44. if (hours < 0 || hours > 744)
  45. {
  46. cout << "Error: Hours must be between 0 and 744." << endl;
  47. return 0;
  48. }
  49. else
  50. {
  51. cout << "You used " << hours << " hours.\n";
  52. }
  53. // Calculate the bill based on the package
  54. if (package == 'A')
  55. {
  56. bill = 9.95;
  57.  
  58. if (hours > 10)
  59. {
  60. bill += (hours - 10) * 2.00;
  61. }
  62. }
  63. else if (package == 'B')
  64. {
  65. bill = 14.95;
  66.  
  67. if (hours > 20)
  68. {
  69. bill += (hours - 20) * 1.00;
  70. }
  71. }
  72. else if (package == 'C')
  73. {
  74. bill = 19.95;
  75. }
  76.  
  77. // Display the total bill
  78. cout << fixed << setprecision(2);
  79. cout << "Total amount due for this month's internet bill: $" << bill;
  80. cout << endl;
  81.  
  82. return 0;
  83. }
Success #stdin #stdout 0.01s 5308KB
stdin
B 67
stdout
Select your internet plan (A, B, or C).
You have internet plan B.
Enter the number of hours used.
You used 67 hours.
Total amount due for this month's internet bill: $61.95