Create a C – BMI Calculator. This is a console application (Code::Blocks). Creat
ID: 3767008 • Letter: C
Question
Create a C – BMI Calculator. This is a console application (Code::Blocks).
Create a main function that asks the user for two floats, height and weight, calls a function to compute BMI (below), then prints out the input and results.
With the results, create an if statement that prints out (along with the BMI), the keywords “Underweight” (BMI<=18.5), “Normal” (18.5<BMI<=25), “Overweight” (25<BMI<=30), or “Obese” (BMI>30).
Write a floating point function that returns BMI given two floating point arguments: weight and height. BMI = 703*W/H^2; Call this function were appropriate in main in order to compute BMI.
Compile main and the sub-function to produce an executable. Execute the code once for height = 70 and weight = 140.
Explanation / Answer
Here is the code for you. If you need any further clarifications, just revert to me.
#include <stdio.h>
float computeBMI(float height, float weight)
{
return 703 * weight / (height * height); /*Returns the BMI.*/
}
int main()
{
float height, weight, BMI;
printf("Enter the height: "); /*Reads the height.*/
scanf("%f", &height);
printf("Enter the weight: "); /*Reads the weight.*/
scanf("%f", &weight);
BMI = computeBMI(height, weight); /*Calls the function to calculate BMI.*/
printf("Your height: %.2f ", height); /*Prints height.*/
printf("Your weight: %.2f ", weight); /*Prints weight.*/
printf("BMI Calculated: %.2f ", BMI); /*Prints BMI.*/
if(BMI <= 18.5) /*Prints final message.*/
printf("You are UnderWeighted. ");
else if(BMI <= 25)
printf("You are NormalWeighted. ");
else if(BMI <= 30)
printf("You are OverWeighted. ");
else
printf("You are Obese... ");
}