fork download
  1. //Cameron Pham CS1A Chapter 4, P. 222, #12
  2. //
  3. /*******************************************************************************
  4. *
  5. * Calculate Bank Service Fees
  6. * ______________________________________________________________________________
  7. * This program accepts values for a beginning account balance and the number
  8. * of checks written. It then calculates the bank's monthly service fees based
  9. * on the given information.
  10. * ______________________________________________________________________________
  11. * INPUT
  12. * Beginning balance
  13. * Number of checks written
  14. * Check fees
  15. * Service fees
  16. *
  17. * OUTPUT
  18. * Total bank service fees for the month
  19. *******************************************************************************/
  20. #include <iostream>
  21. #include <iomanip>
  22. using namespace std;
  23.  
  24. int main() {
  25. double beginningBalance;
  26. int checks;
  27. double checkFee;
  28. double serviceFee;
  29.  
  30. cout << "Enter the beginning balance\n";
  31. cin >> beginningBalance;
  32. cout << "You entered: $" << beginningBalance << endl;
  33.  
  34. // Check for negative beginning balance
  35. if (beginningBalance < 0)
  36. {
  37. cout << "URGENT: The account is overdrawn!" << endl;
  38. return 0;
  39. }
  40.  
  41. cout << "Enter the number of checks written\n";
  42. cin >> checks;
  43. cout << "You entered: " << checks << " checks" << endl;
  44.  
  45. // Check for negative number of checks
  46. if (checks < 0)
  47. {
  48. cout << "ERROR: The number of checks cannot be negative." << endl;
  49. return 0;
  50. }
  51.  
  52. // Determine the check fee
  53. if (checks < 20)
  54. {
  55. checkFee = 0.10;
  56. }
  57. else if (checks <= 39)
  58. {
  59. checkFee = 0.08;
  60. }
  61. else if (checks <= 59)
  62. {
  63. checkFee = 0.06;
  64. }
  65. else
  66. {
  67. checkFee = 0.04;
  68. }
  69.  
  70. // Calculate monthly service fee
  71. serviceFee = 10.00 + (checks * checkFee);
  72.  
  73. // Add $15 fee if balance is below $400
  74. if (beginningBalance < 400)
  75. {
  76. serviceFee += 15.00;
  77. }
  78.  
  79. cout << fixed << setprecision(2);
  80. cout << "Bank service fees for the month: $" << serviceFee << endl;
  81.  
  82. return 0;
  83. }
Success #stdin #stdout 0.01s 5280KB
stdin
200.67 18
stdout
Enter the beginning balance
You entered: $200.67
Enter the number of checks written
You entered: 18 checks
Bank service fees for the month: $26.80