I need help writing a BMI calculation C program that follows these guidlines. It
ID: 3792405 • Letter: I
Question
I need help writing a BMI calculation C program that follows these guidlines. It must be a C program.
Part 2: BMI Calculation:
One measurement of a person’s fitness is their Body Mass Index. The United States Center for Disease Control uses this to classify people as normal, underweight, overweight, or obese, according to the following table:
BMI
Classification
Less than 18.5
Underweight
18.5 – less than 25
Normal
25.0 – less than 30
Overweight
30.0 and above
Obese
The formula that is used to calculate BMI is
BMI= (703xweight in pounds)/(height in inches)^2
You are to write a program which includes two functions:
A function (calculate_bmi), that takes as arguments a person’s weight in pounds and height in inches (both doubles) and returns a bmi_index calculated with the above formula.
A function (print_bmi), that takes the value of the bmi and prints an appropriate message to the screen showing the bmi(using 1 decimal place) and the classification.
Your main will then
Ask the user for their weight and height.
Call the calculate_bmi function and store the result in a variable.
Call print_bmi function to output the results based on the calculated bmi. The function should tell the person how they are classified. You will be doing this through a series of nested if/else statements.
BMI
Classification
Less than 18.5
Underweight
18.5 – less than 25
Normal
25.0 – less than 30
Overweight
30.0 and above
Obese
Explanation / Answer
#include <stdio.h>
/*Variables Used:
bmi_index/bmi= Contains the value of the calculated BMI based upon the given weight and height
weight = Contains the weight in Pounds
height = Contains the height in inches
*/
/*This function is used to calculate BMI
with given weight in pounds and height in inches*/
double calculate_bmi(double weight, double height)
{
double bmi_index=(703*weight)/(height*height);
return bmi_index;
}
/*This function outputs the result based on the
calculated bmi.The value of the bmi is passes as
an arguement */
void print_bmi(double bmi)
{
printf("%lf ",bmi);
if(bmi<18.5)
printf("Underweight");
else if(bmi>=18.5 && bmi<25)
printf("Normal");
else if (bmi>=25 && bmi<30)
printf("Overweight");
else
printf("Obese");
}
int main()
{
double weight, height;
printf("Enter the weight in pounds ");
scanf("%lf", &weight);
printf("Enter Height in Inches ");
scanf("%lf", &height);
double bmi=calculate_bmi(weight,height);
print_bmi(bmi);
return 0;
}