Why is my code not outputting correctly? 🤷🏼‍♂️ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is my code not outputting correctly? 🤷🏼‍♂️

This is a pretty simple code where you enter your systolic and diastolic blood pressures and whether you are in a healthy range is outputted. However, if you enter 140 for systolic and 80 for diastolic, that is stage 2 hypertension which is what is in the code but the output is stage 1. Any ideas why? Any help is much appreciated!! https://code.sololearn.com/c0J1Zop5401S/?ref=app

29th Mar 2020, 12:13 AM
Kyle Barthelmes
Kyle Barthelmes - avatar
3 Answers
+ 1
Stage 1 the condition is 120<=S<=129 OR 80<=D<=89. That is, if either S or D matches, the condition will be true. S = 140 doesn't match, but D = 80 matches. If you want the condition is false, use &&
29th Mar 2020, 1:28 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Makes sense thanks!
29th Mar 2020, 3:27 AM
Kyle Barthelmes
Kyle Barthelmes - avatar
0
I found the answer. I DO want to use OR because only one of the conditions has to be true to qualify for stage 1 or 2, etc. But if I reverse the order of the else if statements it checks stage 2 before stage 1 and it comes out right.
29th Mar 2020, 3:38 AM
Kyle Barthelmes
Kyle Barthelmes - avatar