2016-10-11 63 views
-2
 //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。我的程序似乎没有按照我的如果语句

此外,如果我输入的重量或高度低于或高于要求,它不显示错误消息,只是继续然后关闭。

+0

这是学习使用调试器的好时机。它将允许您一次完成一行,准确查看发生了什么。 –

回答

1

如果您正在检查范围5和120之间,它应该如下,因为height < 5 && height > 120将返回false。

if (height > 5 && height < 120) 
    { 
    Console.WriteLine("The height entered must be between 5” and 120” inclusive."); 
    } 

同样重量,

if (weight > 0.5 && weight < 999) 
{ 
    Console.WriteLine("The weight entered must be between 0.5 lb. and 999 lb. inclusive."); 
} 
如果你想看到控制台输出,在节目的末尾添加此

Console.ReadLine() 

将等待,直到用户按一些密钥

0

在程序结束时添加Console.ReadLine并保持打开状态。

0

最后添加一个额外的Console.ReadLine或Console.ReadKey。这将迫使控制台应用程序等待用户在退出之前输入enter或任何其他键。

相关问题