You are joking, aren't you?
You perform:
runningBalance += depositAmount;
totalDeposits += depositAmount;
_before_ your input validation of the deposit amount.
You perform:
totalWithdrawals += withdrawAmount;
_before your input validation of the withdrawals amount.
Then _why_ are surprised that the values gets changed even for negative
inputs. Why wouldn't they? How long did you spend looking for this error,
before settling for Internet Personal Guidance?
By the way: What's wrong with standard text mails? Are they too easy to
read, or do they consume too little bandwidth?
It is way better to try and find a way to post your source code using a
method that keeps the indentation (you do indent your code?), than in a
way where you can mark some source lines in bold. If you feel you need to
mark a spot, it is enough with a "<=== Problem here" note in the text.
/pwm
On Fri, 14 Mar 2008, Shawn wrote:
> I'm having something strange occur. When someone enters a negative
> number in my program for either the deposit amount or the withdrawal
> amounts, it loops and prompts for the user again...but it also subtracts
> the negative number from my running total! Shouldn't the input
> validation keep that from happening? Am I missing something? The code
> is below with the suspected portions highlighted ...thanks!
|