if, and, or.......uh...?

I know, I'm dating myself here but I feel like the old Saturday morning School House Rock song....."conjunction, conjunction, what's your function". I know what I need but I cant quite seem to hook them together.

I'm trying to diagram the flow this conditional statement:

If the withdrawal causes the available balance to fall below $5 charge a service fee of $1 but if the combined withdrawal amount and service charge puts the account in a negative balance, deny the withdrawal. I cant figure out if that can be placed in one if statement.....
You have three actions to take.
- Approve
- Apply a service charge
- Deny

You can't have three different actions with a single if. Therefore, you need two if statements.
That's kind of what I was thinking but wasn't sure if there was a creative way to "conditionalize" that.

Once again.....THANKS!
closed account (48T7M4Gy)
If the withdrawal causes the available balance to fall below $5 charge
if ( ( balance - withdrawal < 5) a service fee of $1 but if the combined withdrawal amount and service charge puts the account in a negative balance, deny the withdrawal.

1
2
3
4
if( ( balance - withdrawal < 5) && (balance - withdrawal - service fee) > 0 ) )
   balance -= ( withdrawal + service fee ) ;
else
   withdrawal = 0;

Last edited on
@kemort - You're missing the condition of no service charge if the balance does not drop below $5 (what I referred to as approve).
closed account (48T7M4Gy)
The if statement quoted in the OP and in turn the one I re-quoted doesn't address the extra condition or state you have imposed. Sorry, but you're not correct. I haven't missed anything.
Last edited on
It's a poorly worded requirement. If you take what was written in the original request, there are only two conditions. However, the OP does not address what to do if the the balance is > $5. The implication is there is no service charge. That was my point.
closed account (48T7M4Gy)
Counterfactuals are always very shaky grounds for a critique in the first place and now an inadequate apology for rushing to judgment on my contribution.

I understand and understood at the time your point. But that still leaves your claim that I have missed something or anything clearly false. That's my point. ;)
Last edited on
I will have to check the requirements but it sounds that I may have left out the requirement for the below $5 problem.
closed account (48T7M4Gy)
Seems to be a bit late unless you're trying to make the same dumb counterfactual point too?
Last edited on
@kemort......Unfortunately, I'm not smart enough to make those kinds of points. My inquiry here is neither affectation nor spurious in nature. I'm just an old man trying to learn new tricks. but then again, I could be wrong...
The issue is that the original problem statement does not indicate what should be done if the withdrawal should not fall below $5, and AbstractionAnon and kemort both interpreted it differently.

AA suggests that it is logical to simply approve the withdrawal.
kemort suggested otherwise, imposing no withdrawal in that case.
AA then said that kemort missed the w≥$5 possibility.
kemort is now upset because he was represented as having missed the possibility.

The fact that the original problem statement did not specifically address the w≥$5 possibility does not remove it from needing special consideration. You still have three conditions:
- (balance - withdrawal) ≥ 5
- 0 ≤ (balance - withdrawal - service charge) < 4
- (balance - withdrawal - service charge) < 0

The actual number of actions to be taken depend on the (unspecified) requirements. But not knowing any better it is unsafe to eliminate any possibilities. I would amend AA's original post as:
- Approve Unknown
- Apply a service charge
- Deny

Since your program cannot function without knowing (you must either modify the user's balance or not), you can:
- ask for further specific instruction for the first condition
- assume that the withdrawal cannot be approved (as there is not enough specific information to do it) [kemort's response]
- assume that the withdrawal should be approved unmodified (this is the implied condition -- the requirements only speak on what to do for specific states of the unmodified withdrawal -- the unmodified withdrawal is implied). [AbstractionAnon's response]

The code to do it is a very easily nested if statement:
1
2
3
4
5
6
if (balance - withdrawal >= 5)
  unknown;
else if (balance - withdrawal - 1 < 0)
  deny
else 
  approve (balance - withdrawal)


Hope this helps.
yes it does and I appreciate ALL help.

The above nested if statement is precisely how I structured (on paper) my code based on AA's original suggestion to use the 3 functions. sometimes, I know what I want to do but my brain gets all tongue tied and I start down that rabbit hole.

There is also another condition....what to do to stop the service charges from causing the account from going into a negative balance?

I think that I will ignore this particular problem because it really could not act autonomously unless the data was stored somewhere (registry maybe) and updated daily.

Let me say this though...you guys are an awesome resource and I appreciate the patience and willingness to help shown on this site.
closed account (48T7M4Gy)
I'm not actually upset or even just a smidgen ruffled by the true-to-type behavior of nerds. The wonders of being deprived of human interaction never cease to amaze me.

The interesting point raised that the balance must be modified was something I took into account by not referring to it, believe it or not. A statement by me that balance = balance seemed a bit perverse at the time so I left it out. But I wish I had written it in now and waited for the nerd-it-doesn't-compute response.

AA has also fallen into a trap in that there is no question of approval. It's all in his mind. AA has assumed this, or even worse, you Duoas have assumed he has assumed this. We should only deal with the facts before us, as they say. AA has re-written the problem and broken it down into 3 imaginary parts in order to perform magic and 'prove' that something, an if, can't be done. Proving a negative is very hard to do, some say impossible, and in this case I agree.

But thanks for the contribution Duoas. I'm not pig-headed, simply not convinced, especially when there is a complete lack of evidence and the inevitable failure of counterfactual navel-gazing.

PS Running and disappearing are another set of nerd characteristics. ;)
@Andym
There is no condition preventing service charges from making the balance go negative.

@kemort
I have assumed nothing, only defended your position as well as AA's, as plainly stated by both of you in this thread, and only for the benefit of OP. I have not called you pig-headed or wrong.

PS. Running and disappearing is completely different from refusing to continue to participate in a mud fight.
closed account (48T7M4Gy)
@Duoas

You can't defend both. In fact you don't have to defend either.

To make it clear I am not claiming you have accused me of being pig-headed.

Regrettably both you and AA are reading too much into the problem. You are assuming problem pre and post conditions that don't exist. By believing without foundation, assuming I venture, AA has led himself to a fallacious conclusion. He has deluded himself.

I'll treat the reference to mud fighting with the contempt it deserves. It's as hollow as the 'hope that it helps' phrase is.
Wow, I only wanted to help the OP, never intending a derailment response to any other participant.

The only thing that's hollow here is the contemptuous personal insults you are continuously casting.

Go get your own thread and stop derailing OP's.
Thank you Duoas and AA. Not really sure either how all this topic got so off track. I'm sure to you guys this was a fairly simple question but to a novice like me it was confusing.
closed account (48T7M4Gy)
You go get your own thread Douas. the typical yank response, interfering in everybody's business in the world then start dictating and blubbering when you're called out.
Topic archived. No new replies allowed.