當前位置:編程學習大全網 - 編程語言 - 用C#編寫壹個計算體重指數的控制臺程序。

用C#編寫壹個計算體重指數的控制臺程序。

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("體重指數計算器 \n 使用幫助:根據提示輸入,再按\"回車確定\" ");

start:

Console.WriteLine("輸入妳的身高:單位:米(m)");

double height = Convert.ToDouble(Console.ReadLine());

Console.WriteLine("輸入體重: 單位:千克(kg)");

double weight = Convert.ToDouble(Console.ReadLine());

if (height <= 0 || weight <= 0)

{

Console.WriteLine("妳輸入的數字有誤,按\'1\'重新開始! 註意:按其他鍵將會退出程序!");

byte i = Convert.ToByte(Console.ReadLine());

switch (i)

{

case 1:

goto start;

break;

default:

return;

break;

}

}

else

{

double bmi = weight / (height * height);

Console.WriteLine("妳的體重指數為{0}",bmi );

if (bmi < 18.5)

Console.WriteLine("偏瘦,危險性:低,但其它疾病危險性增加");

else if (bmi >= 18.5 && bmi < 24)

Console.WriteLine("正常,請繼續保持");

else if (bmi >= 24 && bmi < 27)

Console.WriteLine("偏重,危險性:小");

else if (bmi >= 27 && bmi < 30)

Console.WriteLine("肥胖,危險性:中");

else if (bmi >= 30 && bmi < 40)

Console.WriteLine("重度肥胖,危險性:大");

else

Console.WriteLine("極度肥胖,危險性:極大");

}

Console.WriteLine("\n是否想重新使用? 是按\'1\' 否按\'2\'來退出程序。");

byte a = Convert.ToByte(Console.ReadLine());

switch (a)

{

case 1:

goto start;

break;

case 2:

return;

break;

default:

return;

break;

}

Console.ReadKey();

}

}

}

  • 上一篇:中國最年輕最有名的廚師是誰?
  • 下一篇:保定市精工汽車模具技術有限公司怎麽樣
  • copyright 2024編程學習大全網