Hi. I'm having a problem. So I'm making a BMI calculator and everytime I type whatever value, it display 'normal'. Why is this hapenning? Beginner here. i'll show the part of the code which I find its false.
Do not duplicate conditions. Code duplication is bad.
The 'else' already ensures that previous 'if' conditions are false, you do not (and should not) repeat those conditions.
1 2 3 4 5 6 7
// BAD -- don't do this!
if (BMI <= 18.5)
//...
elseif (BMI > 18.5 && BMI < 25)
//...
elseif (BMI >=25 && BMI < 30)
//...
1 2 3 4 5 6 7
//better:
if(BMI <= 18.5)
//...
elseif(BMI < 25) // because of the 'else', we already know BMI is > 18.5. No need to check again
//...
elseif(BMI < 30) // again, because of the 'else', we know BMI >= 25
//...
EDIT:
the original problem was because your conditions were formed poorly:
1 2 3 4 5 6 7 8
if (BMI <= 18.5)
// this covers BMI <= 18.5
elseif (BMI >= 18.5 )
// and this covers BMI >= 18.5
// those 2 conditions cover EVERY POSSIBLE value for BMI
elseif(BMI >= 25)
// so this will never execute, because if BMI is >= 25, it's also >= 18.5, so the
// previous 'if' block would have executed