I am having trouble figuring out why the first if statement doesn't kick in. It is suppossed to catch a user already over the credit limit before doing any processing and end program. Here is the code:
EDIT by mw: Added Code Tags. [ March 03, 2007: Message edited by: marc weber ]
Originally posted by Dan Grindstaff: HHmmm. I put in any account number, then 5 for balance and 4 for credit limit and it just goes on to the next pane and asks for credit and debit information.
Oh, I see what you were expecting. You were thinking it would continuously check for that "if" condition.
But this is a single thread, so these lines of code execute in sequence. In particular, the "if" statement does not execute until it gets to that line of code. It sounds like you want to move that "if" statement to the point at which the validation should happen.
(Note: I've seen this assumption made with "while" loops. People sometimes expect that the loop body should stop the moment the "while" condition becomes false. But the condition is only checked at the beginning of each iteration. If true, then the entire loop body executes before another check is made.) [ March 03, 2007: Message edited by: marc weber ]
Here's what I'm confused about: The "balance" appears to be a credit balance (a debt amount), so it makes sense that a user is overdrawn if this balance is greater than their credit limit. But if that's the case, then to determine newBalance, shouldn't you be subtracting credits (i.e., payments that lower the debt) and adding debits (i.e., increasing the debt)? If so, then your second "if" statement should say "overpaid" instead of "overdrawn."