Lost figuring Out how to add this in

I am at a loss. How do I calculate the following with what is being asked?

"If the balance of the account minus the monthly charge falls below the minimum allowed balance of $400, the bank also charges an extra $15 in maintenance fees. Note: the balance that is compared to the minimum does not include the check fees."

This is the code I have so far. Everything works but the final quote if that balance ends up being below the amount requested after the calculations are done.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  // The following is original code by the student
#include <iostream>
#include <iomanip>

using namespace std;

int main()
// Symbolic Constants Declarations
{
    const double PER_CHECK_FEE = .10;                           // when checks written are < 20
    const double PER_CHECK_FEE2 = .08;                          // when checks written are  >= 20 but < 40
    const double PER_CHECK_FEE3 = .06;                          // when checks written are >= 40 but < 60
    const double PER_CHECK_FEE4 = .04;                          // when checks written are >= 60
    const double MONTHLY_CHARGE = 10.0;                         // monthly fee
    const double MAINT_CHARGE = 15.0;                           // maintenence fee if account balance is < $400.00
    const double MIN_BALANCE = 400.0;
    double balance;                                            // checking account balance
    double num = 0;                                            // balance of checking account.  num=checks written
    double serviceFee;
   
   
    // Gets the user's data on their checking account balance.
    cout << " Please enter the balance of your checking account: ";
    cin >> balance;
    
// next chunk of code for when users account balance is less than 0 or above 0
    if (balance < 0)
    {
        cout << " This account is overdrawn. Have a nice day!  " <<endl;
        
    }

    
 if (balance >= 0)
 {

     cout << "Enter the number of checks written this month:  ";    // This tells the user to enter number of checks written
    cin >> num;
 }
    
    
    if ( num < 0)
    {
        cout << " Checks must be greater than -1. Please re-enter: ";  // when a person puts in a negative check amount.
        cin >> num;
    }
    
    // Next chunk of code dictates the calculations for the total service charges if account balance is < $400
    
    if ( balance < 400.00 && num < 20)
    {
        serviceFee = PER_CHECK_FEE * num + (MAINT_CHARGE + MONTHLY_CHARGE);
        cout << setprecision(2) << fixed<< " \n The service charge for the month is $ " << serviceFee ;
    }
    
    
       else if ( balance < 400.0 && num <= 39 && num >=20)
    {
        serviceFee = PER_CHECK_FEE2 * num + (MAINT_CHARGE + MONTHLY_CHARGE);
        cout << setprecision(2) << fixed << " \n The service charge for the month is $  "<< serviceFee << endl;
        
    }
    
    
       else if( balance < 400.0  && num <= 59 && num >= 40)
    {
        serviceFee = PER_CHECK_FEE3 * num + (MAINT_CHARGE + MONTHLY_CHARGE);
        cout << setprecision(2) << fixed << " \n The service charge for the month is $  " << serviceFee << endl;;
    }
    
    
        else if ( balance < 400  && num > 60)
    {
            serviceFee = PER_CHECK_FEE4 * num +  (MAINT_CHARGE + MONTHLY_CHARGE);
        cout << setprecision(2) << fixed << " \n The service charge for the month is $ " << serviceFee << endl;
    }
    
    // Next chunk of codes dictates service charges caluclation totals for account balances > $400.00
    
        else if ( MIN_BALANCE >= 400.0 && num <= 39 && num >= 20)
      {
          serviceFee = PER_CHECK_FEE2 * num + MONTHLY_CHARGE;
          cout << setprecision(2) << fixed << " \n The service charge for the month is $ " << serviceFee << endl;
      }
    
    
      else if ( MIN_BALANCE >= 400.0 && num <= 59 && num >= 40)
      {
          serviceFee = PER_CHECK_FEE3 * num + MONTHLY_CHARGE;
          cout << setprecision(2) << fixed<< " \n The service charge for the month is $ " << serviceFee << endl;
      }
    
      else if ( MIN_BALANCE >= 400.0 && num > 60)
    {
        serviceFee = PER_CHECK_FEE4 * num + MONTHLY_CHARGE;
        cout << setprecision(2) << fixed<< " \n The service charge for the month is $ " << serviceFee << endl;
    }
    
  
    
    return 0;
    
}
"If the balance of the account minus the monthly charge falls below the minimum allowed balance of $400, the bank also charges an extra $15 in maintenance fees. Note: the balance that is compared to the minimum does not include the check fees."


A good tip is to try and take paragraphs like this and break them down one sentence at a time into pseudocode, such that:
1
2
3
4
5
if ((balance - monthCharge ) < monthBalance)
{
    balance -= maintFee;
}
balance = balance - balance*checkFee;
I now have the following code in place. It gives me the answer but I'm getting two different answers as well. I've added finalBalance as a double variable as well. This is the answer I get. The 10.00 should be the right answer. I have no clue why its adding the 15 as well.

Please enter the balance of your checking account: 6125.01
Enter the number of checks written this month: 0

The service charge for the month is $ 10.00

The service charge for the month is $ 25.00
Program ended with exit code: 0


if (finalBalance < MIN_BALANCE)
{
finalBalance = balance + MONTHLY_CHARGE;
serviceFee = serviceFee + MAINT_CHARGE;
cout << setprecision(2) << fixed<< " \n The service charge for the month is $ " << serviceFee << endl;
}
Then the problem should lie in another part of the code that has something to do with service fee. I'm not seeing anything wrong with the snippet of code you have above, unless you accidentally changed the value you assigned your const variables. Also why do you have two "service charge" statements printed out?
Because the output is supposed to equal to the serviceFee charges. For example the serviceFee charge could just be with the monthly fee added. so that serviceFee charge also needs the 15 dollar MAINT_CHARGE added to that fee if that finalBalance falls below the min 400.00.
1) That doesn't answer the question of why you need two cout statements with the exact same words. It's not like a receipt where there's a clear difference in amounts SUBTOTAL and TOTAL.

2) Post your revised code, because if you can't tell what's going on with edited code, we sure as hell can't either. Not when we can't even see it.
Topic archived. No new replies allowed.