fork download
  1. /* 10/24/25
  2.  This program helps you calculate your monthly mobile phone bill based on your
  3.   subscription package and the number of minutes you have used. Additionally, it will
  4.   show you how much money you could save if you chose a different package.
  5.  */
  6.  
  7. #include <iostream>
  8. #include <iomanip>
  9.  
  10. using namespace std;
  11.  
  12. int main(){
  13. //Declares and initialized constants for package A
  14. const float packAFee = 39.99;
  15. const int packAMin = 450;
  16. const float packAMinFee = 0.45;
  17.  
  18. //Declares and initialized constants for package B
  19. const float packBFee = 59.99;
  20. const int packBMin = 900;
  21. const float packBMinFee = 0.40;
  22.  
  23. //Declares and initialized constants for package C
  24. const float packCFee = 69.99;
  25.  
  26. //Declares user variables
  27. int packageType;
  28. float userFee;
  29. int userMin;
  30. int numMin;
  31. float amountDue;
  32.  
  33. //Prompts user to enter their package type
  34. cout << "Select a subscription package:\n1. Package A\n2. Package B"
  35. << "\n3. Package C\n4. Quit" << endl;
  36.  
  37. cin >> packageType;
  38.  
  39. //Decides whether user entered a valid package type
  40. switch(packageType){
  41. case(1):
  42. userFee = packAFee;
  43. break;
  44. case(2):
  45. userFee = packBFee;
  46. break;
  47. case(3):
  48. userFee = packCFee;
  49. break;
  50. case(4):
  51. return 0;
  52. default:
  53. cout << "The valid choices are 1 through 4. Run the"
  54. << "\nprogram again and select one of those.";
  55. return 0;
  56. }
  57.  
  58. //Prompts user for the number of minutes they used
  59. cout << "How many minutes were used? ";
  60. cin >> numMin;
  61.  
  62. int tempMin = numMin; //creates a copy of numMin
  63.  
  64. //Calculates the amount due based on package type
  65. if(packageType == 1){
  66. tempMin -= packAMin;
  67. if(tempMin < 0)
  68. tempMin = 0;
  69. amountDue = packAFee + tempMin * packAMinFee;
  70. }
  71. else if(packageType == 2){
  72. tempMin -= packBMin;
  73. if(tempMin < 0)
  74. tempMin = 0;
  75. amountDue = packBFee + tempMin * packBMinFee;
  76. }
  77. else
  78. amountDue = packCFee;
  79.  
  80. //Outputs the amount due to the user
  81. cout << "The total amount due is $" << amountDue << endl;
  82.  
  83. //Declares temporary variables to find potential savings
  84. char tempPack1, tempPack2;
  85. float tempDue1, tempDue2;
  86.  
  87. //Decides which packages need to be compared
  88. switch(packageType){
  89. case(1):
  90. tempPack1 = 'B';
  91. tempPack2 = 'C';
  92. break;
  93. case(2):
  94. tempPack1 = 'A';
  95. tempPack2 = 'C';
  96. break;
  97. case(3):
  98. tempPack1 = 'A';
  99. tempPack2 = 'B';
  100. break;
  101. }
  102.  
  103. //resets tempMin to its original value
  104. tempMin = numMin;
  105.  
  106. //Calculates the amount due based on the package
  107. if(tempPack1 == 'A'){
  108. tempMin -= packAMin;
  109. if(tempMin < 0)
  110. tempMin = 0;
  111. tempDue1 = packAFee + tempMin * packAMinFee;
  112. }
  113. else if(tempPack1 == 'B'){
  114. tempMin -= packBMin;
  115. if(tempMin < 0)
  116. tempMin = 0;
  117. tempDue1 = packBFee + tempMin * packBMinFee;
  118. }
  119. else
  120. tempDue1 = packCFee;
  121.  
  122. //resets tempMin to its original value
  123. tempMin = numMin;
  124.  
  125. //Calculates the amount due based on the package
  126. if(tempPack2 == 'A'){
  127. tempMin -= packAMin;
  128. if(tempMin < 0)
  129. tempMin = 0;
  130. tempDue2 = packAFee + tempMin * packAMinFee;
  131. }
  132. else if(tempPack2 == 'B'){
  133. tempMin -= packBMin;
  134. if(tempMin < 0)
  135. tempMin = 0;
  136. tempDue2 = packBFee + tempMin * packBMinFee;
  137. }
  138. else
  139. tempDue2 = packCFee;
  140.  
  141. //Decides whether there are savings and outputs the amount for each package
  142. cout << "Savings with Package " << tempPack1 << ": ";
  143. cout << fixed << setprecision(2);
  144.  
  145. if(tempDue1 < amountDue)
  146. cout << "$" << amountDue - tempDue1 << endl;
  147. else
  148. cout << "No Saving!" << endl;
  149.  
  150. cout << "Savings with Package " << tempPack2 << ": ";
  151.  
  152. if(tempDue2 < amountDue)
  153. cout << "$" << amountDue - tempDue2 << endl;
  154. else
  155. cout << "No Saving!" << endl;
  156. }
  157.  
Success #stdin #stdout 0.01s 5328KB
stdin
1 
451
stdout
Select a subscription package:
1. Package A
2. Package B
3. Package C
4. Quit
How many minutes were used? The total amount due is $40.44
Savings with Package B: No Saving!
Savings with Package C: No Saving!