fork download
  1. //Cecilia Rangel CSC5 Chapter 4, P. 225, #23
  2. //
  3. /**************************************************************
  4.  *
  5.  * Computing mobile service charge
  6.  * ____________________________________________________________
  7.  * This program computes which number is the smaller or bigger
  8.  * out of two numbers prompted by the user
  9.  *
  10.  * Computation is based on the following formulas:
  11.  * Additional (Add'l) minutes = Total minutes - Minutes included
  12.  * Charge = Base charge + Add'l minutes * Add'l minute rate
  13.  *___________________________________________________________
  14.  * CONSTANTS
  15.  * packageA : Menu choice for Package A
  16.  * packageB : Menu choice for Package B
  17.  * packageC : Menu choice for Package C
  18.  *
  19.  * INPUT
  20.  * packageChoice : User choice among menu options
  21.  * totalMin : Number of minutes used by user
  22.  * base_A : Base charge for Package A
  23.  * minIncl_A : Number of minutes included with base charge
  24.  * of Package A
  25.  * addlMinRate_A : Rate of charge per add'l minute for Package A
  26.  * base_B : Base charge for Package B
  27.  * minIncl_B : Number of minutes included with base charge
  28.  * of Package B
  29.  * addlMinRate_B : Rate of charge per add'l minute for Package B
  30.  * base_C : Base charge for Package C
  31.  *
  32.  * OUTPUT
  33.  * addlMin : Add'l minutes to be charged extra
  34.  * charge : Total charge for service
  35.  *
  36.  **************************************************************/
  37. #include <iostream>
  38. #include <iomanip>
  39. using namespace std;
  40.  
  41. int main() {
  42. const int packageA = 1; // CONSTANT - Menu choice for Package A
  43. const int packageB = 2; // CONSTANT - Menu choice for Package B
  44. const int packageC = 3; // CONSTANT - Menu choice for Package C
  45.  
  46. int packageChoice; // INPUT - User choice among menu options
  47. int totalMin; // INPUT - Number of minutes used by user
  48. double base_A = 39.99; // INPUT - Base charge for Package A
  49. int minIncl_A = 450; // INPUT - Number of minutes included with
  50. // base charge of package A
  51. double addlMinRate_A = 0.45; // INPUT - Rate of charge per add'l minute
  52. // for Package A
  53. double base_B = 59.99; // INPUT - Base charge for Package B
  54. int minIncl_B = 900; // INPUT - Number of minutes included with
  55. // base charge of Package B
  56. double addlMinRate_B = 0.40; // INPUT - Rate of charge per add'l minute
  57. // for Package B
  58. double base_C = 69.99; // INPUT - Base charge for Package A
  59. int addlMin; // OUTPUT - Add'l minutes to be charged extra
  60. double charge; // OUTPUT - Total charge for service
  61. //
  62. // Prompt User to Specify Package and Minutes Used
  63. cout << "1. Package A: $39.99/mo for 450 min. + $0.45/add'l min." << endl;
  64. cout << "2. Package B: $59.99/mo for 900 min. + $0.40/add'l min." << endl;
  65. cout << "3. Package C: $69.99/mo for Unlimited min." << endl << endl;
  66. cout << "Which of the above packages are you subscribed to? (1-3): ";
  67. cin >> packageChoice;
  68. cout << endl << left;
  69. cout << setw(56) << "How many minutes did you use?" << ": ";
  70. cin >> totalMin;
  71. cout << right;
  72. cout << endl;
  73. //
  74. // Calculate Monthly Charge Based on Subscription; Output Results
  75. if (totalMin >= 0)
  76. {
  77. switch (packageChoice)
  78. {
  79. case packageA:
  80. addlMin = totalMin - minIncl_A;
  81. charge = base_A + addlMin * addlMinRate_A;
  82. cout << "Total charge: $" << charge;
  83. break;
  84. case packageB:
  85. addlMin = totalMin - minIncl_B;
  86. charge = base_B + addlMin * addlMinRate_B;
  87. cout << "Total charge: $" << charge;
  88. break;
  89. case packageC:
  90. charge = base_C;
  91. cout << "Total charge: $" << charge;
  92. break;
  93. default:
  94. cout << "You must select your package by entering 1, 2, or 3.";
  95. }
  96. }
  97. else
  98. cout << "Your number of used minutes must be at least 0.";
  99.  
  100. return 0;
  101. }
Success #stdin #stdout 0s 5316KB
stdin
3
860
stdout
1. Package A:  $39.99/mo for 450 min. + $0.45/add'l min.
2. Package B:  $59.99/mo for 900 min. + $0.40/add'l min.
3. Package C:  $69.99/mo for Unlimited min.

Which of the above packages are you subscribed to? (1-3): 
How many minutes did you use?                           : 
Total charge: $69.99