Skip to main content
1-Visitor
July 1, 2015
Solved

Three if Statement Formula

  • July 1, 2015
  • 3 replies
  • 3382 views

Hi All,

I'm a newbie with Mathcad and I'm self taught so I hope this is an easy on for you guys!!

I'm trying to get my head round why this formula doesn't work so any help would be great.

See the attached Mathcad 15 file.

I'm using if statements to pick the correct answer but I can't get it to completely work. At one point I thought I had it but then when you test it there's always one way it fails. grrrrrrrrrrr

Best Regards

Jonno

Best answer by lturek

Andy has already stated the problem with your (and Alans) routine.

The expression

yield1.png

will always simplify to TRUE and so despite  the returns also Alans approach would yield AllowYield everytime, disregarding the value of Yield.

Here is an alternative approach which I guess does what you had in mind.

yield2.png

You might consider turning the routine into a function to be more versatile.

3 replies

19-Tanzanite
July 1, 2015

Use the return statement to force the program to exit. Without that, as you note, it will always drop through to he next line.

12-Amethyst
July 1, 2015

alternate suggestion.

1. the Boolean operators take 2 logical inputs so where you write IF yield = 60 OR 75, Mathcad checks if yield =60 is true; or if 75 is true. any non zero number is true so therefore 75 = true

This needs to be written IF yield=60 OR yield =75

2 you need to consider the logic of the next statement : IF yield NOT= 60 OR yield NOT=75

one of the statements must be true so this will always be true.

it needs to change to: IF yield NOT= 60 AND yield NOT=75.

Hope this helps

Andy

19-Tanzanite
July 1, 2015

This needs to be written IF yield=60 OR yield =75

Oops! Good catch. I missed that

Jonnox1-VisitorAuthor
1-Visitor
July 2, 2015

Thanks for answering my question Richard!!!

lturek1-VisitorAnswer
1-Visitor
July 1, 2015

Andy has already stated the problem with your (and Alans) routine.

The expression

yield1.png

will always simplify to TRUE and so despite  the returns also Alans approach would yield AllowYield everytime, disregarding the value of Yield.

Here is an alternative approach which I guess does what you had in mind.

yield2.png

You might consider turning the routine into a function to be more versatile.

Jonnox1-VisitorAuthor
1-Visitor
July 2, 2015

Thanks Leopold!!

This works great and you have shortened my formula!!!