我输入体重和身高,最终得到了BMI的结果。感谢您对此问题的帮助和考虑
double height = 0.0;
double weight = 0.0;
double bmi = height / weight;
double bmi = height / weight;
Console.Write("Enter your height in m:");
height = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter your weight in kg:");
weight = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Your BMI is:{0}", Math.Round(bmi,4));
bmi = Convert.ToDouble(Console.ReadLine());
Console.ReadKey();
答案 0 :(得分:0)
您在分配bmi
和height
之前计算weight
。它们的初始值为0,因此您有一个被零除的情况,这导致NaN:
double height = 0.0;
double weight = 0.0;
double bmi = height / weight;
bmi
没有自动更新。您需要首先分配height
和weight
,然后计算bmi
。
Console.Write("Enter your height in m:");
double height = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter your weight in kg:");
double weight = Convert.ToDouble(Console.ReadLine());
double bmi = height / weight;
Console.WriteLine("Your BMI is:{0}", Math.Round(bmi,4));