//Declarations
double height;
double weight;
double BMI;
int Const;
//Reading User Input
//HEIGHT
Console.WriteLine("Please enter the person's height in inches: ");
height = Convert.ToDouble(Console.ReadLine());
if (height < 5 && height > 120)
{
Console.WriteLine("The height entered must be between 5” and 120” inclusive.");
}
//MASS
Console.WriteLine("Please enter the person's weight in lbs: ");
weight = Convert.ToDouble(Console.ReadLine());
if (weight < 0.5 && weight > 999)
{
Console.WriteLine("The weight entered must be between 0.5 lb. and 999 lb. inclusive.");
}
//BMI Calculations
Const = 703;
BMI = (weight/(height * height)) * Const;
//Category Assignments
if (BMI <= 16)
{
Console.WriteLine("The BMI for a " + height + "tall person who weighs " + weight + " lb. is 26.7, which is categorized as 'serverly underwieght'.");
}
else if (BMI > 16 && BMI <= 18.5)
{
Console.WriteLine("The BMI for a " + height + "tall person who weighs " + weight + " lb. is 26.7, which is categorized as 'underwieght'.");
}
else if (BMI > 18.5 && BMI <= 25)
{
Console.WriteLine("The BMI for a " + height + "tall person who weighs " + weight + " lb. is 26.7, which is categorized as 'healthy'.");
}
else if (BMI > 25 && BMI < -30)
{
Console.WriteLine("The BMI for a " + height + "tall person who weighs " + weight + " lb. is 26.7, which is categorized as 'Overweight'.");
}
else if (BMI > 30)
{
Console.WriteLine("The BMI for a " + height + "tall person who weighs " + weight + " lb. is 26.7, which is categorized as 'Obese'.");
}
}
}
}
最初の質問は正しいフォーマットをしていないことです。とにかく、瞬間的に体重を入力した後、私のプログラムが閉鎖されます。そのコンソールアプリケーションbtw。私のプログラムは私のIf文に従っていないようです。
また、要件の下または上にある重量または高さを入力すると、エラーメッセージが表示されず、ただちに終了して終了します。
これは、デバッガの使用方法を学ぶのに最適な時間です。一度に1行ずつステップを踏んで、何が起こっているのかを正確に確認することができます。 –