Help With This Problem of Code

I am having issues here and trying to figure out where I went wrong. Any help would be appreciated. So far I have this code but getting a couple errors near the end. Basically the last four conditions when I'm supposed to be over the minimum balance. Thanks for all your help. I'm rather stumped right now and don't know how to proceed to make this work. I absolutely need to have the const doubles in there as part of this program.

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
 
#include <iostream>
#include <iomanip>

using namespace std;

int main()
    // Symbolic Constants Declarations
{
    const double PER_CHECK_FEE = 0.10;
    const double PER_CHECK_FEE2 = 0.08;
    const double PER_CHECK_FEE3 = 0.06;
    const double PER_CHECK_FEE4 = 0.04;
    const double MONTHLY_CHARGE = 10.0;
    const double MAINT_CHARGE = 15.0;
    const double MIN_BALANCE = 400.0;
    int checks = 0;
    int balance;
    double serviceFee;
    
    cout << " Please enter the balance of your checking account: " << endl;
    cin >> balance;
    
    if (balance < 0)
    {
        cout << " This account is overdrawn. Have a nice day!";
        
        return 0;
    }
    
    if (balance > 0)
    {
        cout << "Enter the number of checks written this month:  ";
        cin >> checks;
    }
    
    if ( balance < 400 && checks < 20)
    {
        serviceFee = (PER_CHECK_FEE * checks) + (MAINT_CHARGE + MONTHLY_CHARGE);
        cout << "The service charge for the month is $ " << serviceFee;
    }
    else if ( balance < 400.0 && checks <= 39 && checks >=20)
    {
        serviceFee = (PER_CHECK_FEE2 * checks) + (MAINT_CHARGE + MONTHLY_CHARGE);
        cout << "The service charge for the month is $ " << serviceFee;
        
    }
    else if ( balance < 400 && checks <= 59 && checks >= 40)
    {
        serviceFee = (PER_CHECK_FEE3 * checks) + (MAINT_CHARGE + MONTHLY_CHARGE);
        cout << " The service charge for the month is $  " << serviceFee;
    }
    else if ( balance < 400 && checks > 60)
        serviceFee = (PER_CHECK_FEE4 * checks) + ( MAINT_CHARGE + MONTHLY_CHARGE);
        cout << " The service charge for the month is $ " << serviceFee;
    }


    if ( balance > 400 && checks < 20)
    {
        serviceFee = (PER_CHECK_FEE * checks) + MONTHLY_CHARGE;
        cout << " The service charge for the month is $ " << serviceFee;
    }
    
    else if ( balance > 400 && checks <= 39 && checks >= 20)
    {
        serviceFee = (PER_CHECK_FEE2 * checks) + MONTHLY_CHARGE;
        cout << " The service charge for the month is $ " << serviceFee;
    }
    
    else if ( balance > 400 && checks <= 59 && checks >= 40)
    {
        serviceFee = (PER_CHECK_FEE3 * checks) + MONTHLY_CHARGE;
        cout << " The service charge for the month is $ " << serviceFee;
    }
    
    else if ( balance > 400 && checks > 60)
    {
        serviceFee = (PER_CHECK_FEE4 * checks) + MONTHLY_CHARGE;
        cout << " The service charge for the month is $ " << serviceFee;
    }
    
        
   
    
return 0;
        
}
When you get compiler errors, it is helpful if you post the full text of the error messages.

Line 54: You're missing an {

Other than that, your program compiles fine.

Last edited on
When I run the program though it takes it right to the end like in a loop instead of calculating correctly. Here is what it does:

" Please enter the balance of your checking account: 342.51
Enter the number of checks written this month: The service charge for the month is $ 10Program ended with exit code: 0"
Line 22: balance is an int. If you try to enter 342.51, only the 342 is read. the ".51" is left in the cin buffer. Then at line 34 when you try to cin checks which is also an int, the cin fails because "." is the next character in the cin buffer and is not a valid character for an int.

If you want to enter decimal numbers, change balance to a double


Ah ok thank you. Something simple. I'll get this down eventually. Still learning.
Topic archived. No new replies allowed.