2016-10-11 75 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或任何其他鍵。

相關問題