Body Check: How to Calculate Your BMI Using a C Program

Introduction:

In this article, we will discuss a program written in C language that calculates the body mass index (BMI) of an individual based on their height and weight. The program will then interpret the BMI result to determine if the individual is underweight, normal weight, overweight or obese, and if obese, which class of obesity the individual falls into.

What is BMI? BMI is a measure of body fat based on a person's height and weight. It is calculated by dividing the weight in kilograms by the height in meters squared. BMI is widely used as a screening tool to identify whether an individual is underweight, normal weight, overweight or obese.

Let's take a look at the code:

#include <stdio.h>

/**

* main - my second project BMI calculator

* description - a program that accept inputs from a user's

* height and weight and print the interpretation of the user's BMI

*/

int main()

{

double height, weight, height_squared, BMI;

printf("Enter your weight in kilograms ");

scanf("%lf", &weight);

printf("Enter your height in meters ");

scanf("%lf", &height);

height_squared = height*height;

BMI = weight/height_squared;

printf("Your height is %.2lfm\n", height);

printf("Your weight is %.2lfkg\n", weight);

printf("Your BMI is %.2lfkg/m2\n", BMI);

if (BMI < 18)

{

printf("Your are Uderweight");

}

else if (BMI >= 18 && BMI < 25)

{

printf("You are Normal Weight");

}

else if (BMI >= 25 && BMI < 30)

{

printf("You are OverWeight\n");

}

else if (BMI > 30)

{

printf("You are Obesity\n");

if (BMI >= 30 && BMI < 35)

{

printf("Class I Obesity");

}

else if (BMI >= 35 && BMI < 40)

{

printf("Class II Obesity");

}

else

{

printf("Class III Obesity");

}

}

else

{

printf("You BMI is not known");

}

return 0;

}

The Program:

The program starts by declaring four variables: height, weight, height_squared, and BMI, and then prompts the user to enter their height and weight. The user's input is then used to calculate the BMI by dividing the weight by the height squared. The program then prints out the user's height, weight, and calculated BMI.

Next, the program uses a series of if-else statements to interpret the calculated BMI result. If the BMI is less than 18, the program prints "You are Underweight". If the BMI is between 18 and 25, the program prints "You are Normal Weight". If the BMI is between 25 and 30, the program prints "You are Overweight". If the BMI is greater than 30, the program prints "You are Obesity" and then checks the BMI against three thresholds to determine which class of obesity the individual falls into. If the BMI is not known or if the user enters invalid inputs, the program prints "Your BMI is not known".

Conclusion:

In conclusion, the program we discussed in this article is a simple yet powerful tool that can be used to determine an individual's BMI and provide an interpretation of their body weight status. BMI is an important measure of health that can help individuals to identify potential health risks associated with obesity. This program serves as a valuable resource for individuals looking to monitor and manage their weight and overall health.