How to use if elseif, if

Underweight: BMI is less than 18.5 Normal weight: BMI is 18.5 to 24.9 Overweight: BMI is 25 to 29.9 Obese: BMI is 30 or more how to use if, elseif, if to Display BMI classification I did:
if(BMI<18.5)
BMI classification='underweight'
elseif(18.5<BMI<24.9)
BMI classification='Normal weight'
else(25<BMI<29.9)
BMI classification='Overweight'
end

Antworten (1)

Youssef  Khmou
Youssef Khmou am 11 Feb. 2013

0 Stimmen

Hi try this :
BMI=input(' Enter BMI : ');
if(BMI<18.5)
classification='underweight'
elseif(18.5<BMI && BMI<24.9)
classification='Normal weight'
else(25<BMI && BMI<29.9)
classification='Overweight'
end

2 Kommentare

THANH NGUYEN
THANH NGUYEN am 11 Feb. 2013
How about obese for BMI greater than 30?
Image Analyst
Image Analyst am 11 Feb. 2013
Bearbeitet: Image Analyst am 11 Feb. 2013
if BMI < 18.5
classification='underweight'
elseif 18.5 <= BMI && BMI < 24.9
classification='Normal weight'
elseif 24.9 <= BMI && BMI < 30
classification='Overweight'
else
classification='Obese'
end

Melden Sie sich an, um zu kommentieren.

Tags

Gefragt:

am 11 Feb. 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by