Bank Program - Interest not working

I have written a banking program. I have tested it and it appears to me that the Interest part of the program is doing the calculations for both Savings and Checking, even though it should only be doing the calculations for whichever type of account is being accessed. In my testing case it was for checking. Can someone take a look and tell me if I need to correct the if statements for that particular section? If I do need to change them, can you just supply pseudo code or just describe as best as possible where it went wrong?

Here is my code:

removed

Thanks,
A
Last edited on
I think there's a problem in your nesting of the Interest Calculations part. I think you need an additional nesting level.

Now, if I have a C account with €2000, I will get these steps:
a) First if (l52): pass -> get 2% interest.
b) First else (l58): skipped.
c) Second if (l65): fail, skipped.
d) Second else (l71): pass -> get 4.5% interest.

Your structure should look like this:
1
2
3
4
5
6
7
8
if (ACCT == 'C') {
    if (BAL < 3000) // 2% interest
    else // 2.5% interest
}
if (ACCT == 'S') {
    if (BAL < 10000) // 3% interest
    else // 4.5% interest
}


That should fix things.

Pro-tip:
Big if-else nesting can be solved by using switch()! Especially your input (D, W, I, Q) is a perfect candidate for this!
Pro-tip 2: You have a lot of duplicate code (e.g. l52 ->l76). Why not make a single function and call it several times?
Here are my corrections:

removed

It is having an issue with a bracket - giving a syntax error. Checked and re-checked and can't find the problem.
Last edited on
Come on man, don't remove your question and fixes. Others might have this problem and we don't want to answer the same problems over and over again.
Topic archived. No new replies allowed.