In: Computer Science
C# PROGRAM
using System;
namespace BMI // Calculating BMI(Body Mass Index)
{
class Program
{
static void Main(string[] args)
{
double height, weight; // Declare two double variables height,
weight
Console.Write("Enter person's height in inches: ");
bool value1 = double.TryParse(Console.ReadLine(), out height); // input height i.e., represent value1
Console.Write("Enter weight in pounds: ");
bool value2 = double.TryParse(Console.ReadLine(), out weight); //
input weight i.e., represent value2
if (!value1 || !value2) // check not valid input values height and
weight
{
Console.WriteLine("Not valid input."); // display invalid
inputs
}
else
{
if (height < 5 || height > 120) // check in height in inches
height<5 or height>120 then,
{
Console.WriteLine("Not valid height."); // display this
Message
}
else if (weight < 0.5 || weight > 999) // else, check wieght
in pounds weight<0.5 or wieght >999 then,
{
Console.WriteLine("Not valid weight."); // display this
message
}
else
{
// else calculate Body Mass Index (BMI) Imperial (means which uses
units of pounds and inches) Formula bmi=
703.0*(weight/(height*height)) units kg/m^2
double bmi = ((weight / (height * height)) * 703.0);
Console.WriteLine($"The BMI for someone who weighs {weight} lbs and
is {height} in tall is " + Math.Round(bmi) + "."); // display BMI
value with rounded using round(bmi)
string catagory = ""; // Declare category means body fact content based on weight and height i.e., calculate bmi
if (bmi < 16) // check bmi<16 then, display 'severly
underweight'
catagory = "severly underweight";
else if (bmi >= 16 && bmi < 18.5) // else, check bmi
in between 16-18.5 then, display 'underweight'
catagory = "underweight";
else if (bmi >= 18.5 && bmi < 25) // else, check bmi
in between 18.5-25 then, display 'healthy'
catagory = "healthy";
else if (bmi >= 25 && bmi < 30) // else, check bmi in
between 25-30 then, display 'overweight'
catagory = "overweight";
else
catagory = "obese"; // else, bmi more than 30 then display
'obese'
Console.WriteLine("BMI Catagory: You are " + catagory + "."); //
display category
}
}
Console.WriteLine("\nPress any key to close the application:");
//newline operator
Console.ReadKey(); //terminates runtime
}
}
}
OUTPUT-1
Enter person's height in inches: 90
Enter weight in pounds: 60
The BMI for someone who weighs 60 lbs and is 90 in tall is 5.
BMI Catagory: You are severly underweight.
Press any key to close the application:
OUTPUT-2
Enter person's height in inches: 125
Enter weight in pounds: 60
Not valid height.
Press any key to close the application: