Win a copy of Functional Reactive Programming this week in the Other Languages forum!

# Class, Method Help

Greenhorn
Posts: 5
I am having a problem with my debit function. Instead of printing "The person has insufficient funds", it just adds a negative to the account.

[Added code tags - see UseCodeTags for details]

Manoj Kumar Jain
Ranch Hand
Posts: 198
Have a look at your method and its If condition

Do you think that the "If" will be evaluated to false in any case ??

Matthew Brown
Bartender
Posts: 4568
9
And welcome to The Ranch!

Greenhorn
Posts: 5
What are you saying? elaborate for me.

Jeff Verdegan
Bartender
Posts: 6109
6
Alvado Bain wrote:What are you saying? elaborate for me.

Please describe exactly which conditions make that false. Please provide sample values that will make that false.

Manoj Kumar Jain
Ranch Hand
Posts: 198
You are saying that
"it just adds a negative to the account. "

It means the If condition

in your debit method is evaluating to true always. Can you find out why its being evaluated to true always.
Will you ever find a case where (balance > (balance-amount) will be false ??

Got my point ? there is a bug in your code which causing this trouble..

One suggestion: Also place a check in code so that user can't enter negative values as this is absurd to make transaction with negative values

Greenhorn
Posts: 5
Jeff Verdegan wrote:
Alvado Bain wrote:What are you saying? elaborate for me.

Please describe exactly which conditions make that false. Please provide sample values that will make that false.

Well i also used the if else Balance < (balance - amount). Wouldn't that do? This worked for me fine in C++, java on the other hand is a handful.

Jeff Verdegan
Bartender
Posts: 6109
6
Jeff Verdegan wrote:
Alvado Bain wrote:What are you saying? elaborate for me.

Please describe exactly which conditions make that false. Please provide sample values that will make that false.

Well i also used the if else Balance < (balance - amount). Wouldn't that do?

Mathematically, exactly when will balance > (balance-amount) be false?

This worked for me fine in C++.

Highly unlikely.

Greenhorn
Posts: 5
Jeff Verdegan wrote:
Jeff Verdegan wrote:
Alvado Bain wrote:What are you saying? elaborate for me.

Please describe exactly which conditions make that false. Please provide sample values that will make that false.

Well i also used the if else Balance < (balance - amount). Wouldn't that do?

Mathematically, exactly when will balance > (balance-amount) be false?

This worked for me fine in C++.

Highly unlikely.

Wow i feel like a fool, i see your point now. HAHAH, pardon my stupidity.

Jeff Verdegan
Bartender
Posts: 6109
6
Wow i feel like a fool, i see your point now. HAHAH, pardon my stupidity.

No problem. Glad the lightbulb finally popped on.

And don't feel bad. We've all been there--staring too long at something and just not seeing what's right in front of our faces. I've been doing this a long time and it still happens to me.