Search code examples
c#readline

BMI formula c# does not


Please help me! BMI is not calculated correctly! What is the mistake here.

 using System;  
 using System.Collections.Generic; 
 using System.Linq;
 using System.Text; 
 using System.Threading.Tasks;


 namespace BMICHECKERARTEHOSER {
     class Program
     {
         static void Main(string[] args)
         {
             Console.WriteLine("Hello, I'm a robot for calculating body mass index!");
             Console.WriteLine("Enter your weight");
             double m = Convert.ToDouble(Console.ReadLine());
             Console.WriteLine(m);
             Console.WriteLine("Enter your height");
             double h = Convert.ToDouble(Console.ReadLine());
             Console.WriteLine(h);
             Console.WriteLine("Your bmi is:");
             double i = Convert.ToDouble(m / (h * h));
             Console.WriteLine(i);

         }
     } }

Solution

  • If you are expect weight is kg and height is cm then

    Add to last row

    Console.ReadKey();
    

    and

    double i = Convert.ToDouble(m / (h * h));
    

    change:

    double i = Convert.ToDouble(m / (h * h)) * 10000; // convert to kg/m^2