Determine the BMI Category

Use IF, ELSE-IF, and ELSE statements to find the body mass index (BMI) category based on user input.

Problem statement

Suppose you have the body mass index (BMI) of a person, and you want to find out if the person is underweight, healthy, overweight, or obese based on the following:

  • obese: BMI is greater than or equal to 30
  • overweight: BMI is greater than or equal to 25 but less than 30
  • healthy: BMI is greater than or equal to 18.5 but less than 25
  • underweight: BMI is less than 18.5

The main steps in problem-solving

Understand the problem

Go over the problem statement carefully and think about the desired output. The output should be one of the four categories: obese, overweight, healthy, or underweight.

Come up with a practical solution

Choose a specific BMI value and determine the correct label. We base our decision on conditions. Since there are multiple conditions, use IF-ELSE-IF statements. The conditions mentioned in the problem can be checked in IF and ELSE-IF statements to get the desired output.

Implement your solution

Execute the solution on different test cases. For instance, if the BMI is 31, the output should be obese.

Pseudocode

INPUT bmi
IF bmi >= 30
    OUTPUT obese
ELSE-IF bmi >=25
    OUTPUT overweight
ELSE-IF bmi >=18.5
    OUTPUT healthy
ELSE
   OUTPUT underweight

Explanation

We input bmi. Then, we use the greater than or equal operator (>=) to find out if bmi is greater than or equal to 30. If so, we output “obese.” If it is not, then we check the condition inside the ELSE-IF statement. If bmi is greater than or equal to 25, we output “overweight.” Note that the output will be “overweight” only if bmi is higher than 25 but less than 30. If bmi is not greater than or equal to 25, check the condition inside the next ELSE-IF statement. If bmi is greater than or equal to 18.5, the output is “healthy.” If all the conditions stated above are false, the instruction in the ELSE block is executed, and the output is “underweight.” Note the sequence of conditions. If bmi is greater than or equal to 18.5 were written first, weights in the upper ranges would also fulfill the condition, which is a logical error.

To further understand how the pseudocode works, enter a value between 0 and 100 (both values inclusive) and press Done:

Get hands-on with 1400+ tech skills courses.