My program asks a user to enter Height, Weight.
Calculated BMI gets printed.
My problem is the output. It is constantly Zero.
height:180
weight:65
Expected output: 20.1
Calculation logic is:
BMI = weight / height^2 (squared)
Where is my error?
My code below:
//declare variables
int weight;
int height;
double BMI;
Console.WriteLine("Please enter your weight:");
weight = int.Parse(Console.ReadLine());//Get weight from keyboard
Console.WriteLine("Please enter your height:");
height = int.Parse(Console.ReadLine());//get height from keyboard
BMI = Math.Sqrt(height);//Square the height
BMI = weight / height;//SET BMI TO WEIGHT DIVIDED BY HEIGHT SQUARED
//if the BMI is less than 25
if (BMI < 25) {
Console.WriteLine("BMI =" + BMI + " Congratulations! your BMI is perfect!."); }
else if (BMI > 30) {
Console.WriteLine("BMI =" + BMI + " Be careful! risks could lead to obesity."); }
else {
Console.WriteLine("BMI =" + BMI + " Please consider seeing a doctor, as you are of high risk of obesity."); }
output I get is:
0