fork download
  1. //Max Kichuk CS1A Chapter 4, P. 226, #23
  2. //
  3. /****************************************************************
  4.  *
  5.  * CALCULATES MONTHLY BILL FOR SERVICE PROVIDER
  6.  * ______________________________________________________________
  7.  * Asks the user to enter the hours used and what
  8.  * package the user has selected. Displays the total amount due
  9.  * according to their hours and package.
  10.  *
  11.  * CALCULATIONS MADE BY:
  12.  *
  13.  * Package A: For $9.95 per month 10 hours of access are provided. Additional hours
  14.  * are $2.00 per hour.
  15.  *
  16.  * Package B: For $14.95 per month 20 hours of access are provided. Additional
  17.  * hours are $1.00 per hour.
  18.  *
  19.  * Package C: For $19.95 per month unlimited access is provided
  20.  * ______________________________________________________________
  21.  *
  22.  * INPUT
  23.  * packagePlan : package plan user has selected
  24.  * hoursUsed : number of hours used on plan
  25.  *
  26.  * OUTPUT
  27.  * totalCost : total cost on plan A/B/C
  28.  *
  29.  **************************************************************/
  30.  
  31. #include <iostream>
  32. #include <iomanip>
  33. #include <string>
  34. using namespace std;
  35.  
  36. int main() {
  37. //Declaring program variables
  38. char packagePlan; // INPUT : plan user is on
  39. float hoursUsed; // INPUT : hours used on plan
  40.  
  41. float totalCost; // OUTPUT : total cost of hours
  42.  
  43. // INPUT : Initialize variables
  44. cout << "Enter the package you are on (A/B/C) and your hours used ";
  45. cout << "separated by a space.\n";
  46. cin >> packagePlan >> hoursUsed;
  47.  
  48. totalCost = 0.0;
  49.  
  50. // OUTPUT : Display the price
  51. switch(packagePlan)
  52. {
  53. case 'a':
  54. case 'A': cout << "You are on Package A.\n";
  55. totalCost += 9.95;
  56. if (hoursUsed > 10) {
  57. hoursUsed-=10;
  58. totalCost += hoursUsed*2;
  59. }
  60. cout << "You owe $" << setprecision(2) << fixed << totalCost << ".";
  61. break;
  62. case 'b':
  63. case 'B': cout << "You are on Package B.\n";
  64. totalCost += 14.95;
  65. if (hoursUsed > 20) {
  66. hoursUsed-=20;
  67. totalCost += hoursUsed;
  68. }
  69. cout << "You owe $" << setprecision(2) << fixed << totalCost << ".";
  70. break;
  71. case 'c':
  72. case 'C': cout << "You are on Package C.\n";
  73. totalCost += 19.95;
  74. cout << "You owe $" << setprecision(2) << fixed << totalCost << ".";
  75. break;
  76. }
  77.  
  78. return 0;
  79. }
Success #stdin #stdout 0s 5472KB
stdin
Standard input is empty
stdout
Enter the package you are on (A/B/C) and your hours used separated by a space.