fork download
  1. //Matthew Santos CS1A Ch. 3, Pg. , #
  2. /***********************************************
  3.  *
  4.  * CALCULATE MONTHLY BILL
  5.  * _____________________________________________
  6.  * Calculates the monthly bill depending on which
  7.  * package is purchased and how many hours are
  8.  * used.
  9.  * _____________________________________________
  10.  * INPUT
  11.  * packageType : package chosen
  12.  * hours : hours used
  13.  * OUTPUT
  14.  * bill : total monthly bill
  15.  ***********************************************/
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. int main() {
  20.  
  21. //Initialize values
  22. int packageType;
  23. float hours;
  24. float bill;
  25.  
  26. //Display menu
  27. cout << "Package 1: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour." << endl;
  28. cout << "Package 2: For $14.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour." << endl;
  29. cout << "Package 3: For $19.95 per month unlimited access is provided." << endl;
  30.  
  31. //Acquire answer
  32. cin >> packageType;
  33. cin >> hours;
  34.  
  35. //Determine monthly bill
  36. switch (packageType){
  37. case 1:
  38. if(hours <= 10)
  39. {
  40. bill = 9.95;
  41. }
  42. else if(hours > 10)
  43. {
  44. bill = 9.95 + 2 * (hours - 10);
  45. }
  46. cout << bill;
  47. break;
  48. case 2:
  49. if(hours <= 2)
  50. {
  51. bill = 14.95;
  52. }
  53. else if(hours > 20)
  54. {
  55. bill = 14.95 + 1.00 * (hours - 20);
  56. }
  57. cout << bill;
  58. break;
  59. case 3:
  60. bill = 19.95;
  61. cout << bill;
  62. break;
  63. }
  64. return 0;
  65. }
Success #stdin #stdout 0.01s 5288KB
stdin
1
40
stdout
Package 1: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour.
Package 2: For $14.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour.
Package 3: For $19.95 per month unlimited access is provided.
69.95