fork download
  1. #include <iostream>
  2. #include <iomanip> // For setting output precision
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. double balance, serviceCharge = 10.0, checkFee = 0.0, extraFee = 0.0;
  8. int numChecks;
  9.  
  10. // Ask for the beginning balance and number of checks written
  11. cout << "Enter the beginning balance: $";
  12. cin >> balance;
  13.  
  14. // Validate the balance to ensure it's not negative
  15. if (balance < 0) {
  16. cout << "Error: The beginning balance cannot be negative.\n";
  17. return 1;
  18. }
  19.  
  20. cout << "Enter the number of checks written: ";
  21. cin >> numChecks;
  22.  
  23. // Validate the number of checks to ensure it's not negative
  24. if (numChecks < 0) {
  25. cout << "Error: The number of checks cannot be negative.\n";
  26. return 1;
  27. }
  28.  
  29. // Determine the check fee based on the number of checks
  30. if (numChecks < 20) {
  31. checkFee = 0.10 * numChecks;
  32. } else if (numChecks >= 20 && numChecks <= 39) {
  33. checkFee = 0.08 * numChecks;
  34. } else if (numChecks >= 40 && numChecks <= 59) {
  35. checkFee = 0.06 * numChecks;
  36. } else {
  37. checkFee = 0.04 * numChecks;
  38. }
  39.  
  40. // If the balance is below $400, add the extra fee
  41. if (balance < 400) {
  42. extraFee = 15.0;
  43. }
  44.  
  45. // Calculate the total service charges
  46. double totalFee = serviceCharge + checkFee + extraFee;
  47.  
  48. // Output the result
  49. cout << fixed << setprecision(2); // Format output to 2 decimal places
  50. cout << "\nBank Service Fees for the Month:\n";
  51. cout << "-----------------------------------\n";
  52. cout << "Base Service Charge: $" << serviceCharge << endl;
  53. cout << "Check Fees: $" << checkFee << endl;
  54. if (extraFee > 0) {
  55. cout << "Extra Fee (Balance below $400): $" << extraFee << endl;
  56. }
  57. cout << "Total Service Charges: $" << totalFee << endl;
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Enter the beginning balance: $Enter the number of checks written: 
Bank Service Fees for the Month:
-----------------------------------
Base Service Charge: $10.00
Check Fees: $881.12
Extra Fee (Balance below $400): $15.00
Total Service Charges: $906.12