用asp.net输入身高体重年龄,在label输出
时间: 2023-03-29 12:00:47 浏览: 69
您好,可以使用以下代码实现:
```
protected void Button1_Click(object sender, EventArgs e)
{
double height = Convert.ToDouble(txtHeight.Text);
double weight = Convert.ToDouble(txtWeight.Text);
int age = Convert.ToInt32(txtAge.Text);
double bmi = weight / (height * height);
string result = "";
if (bmi < 18.5)
{
result = "体重过轻";
}
else if (bmi >= 18.5 && bmi < 24)
{
result = "正常范围";
}
else if (bmi >= 24 && bmi < 28)
{
result = "体重过重";
}
else if (bmi >= 28 && bmi < 30)
{
result = "轻度肥胖";
}
else if (bmi >= 30 && bmi < 35)
{
result = "中度肥胖";
}
else
{
result = "重度肥胖";
}
lblResult.Text = "您的身高是:" + height.ToString() + "米,体重是:" + weight.ToString() + "千克,年龄是:" + age.ToString() + "岁,BMI指数为:" + bmi.ToString("F2") + ",属于" + result + "。";
}
```
其中,txtHeight、txtWeight、txtAge 分别是输入身高、体重和年龄的文本框,Button1 是计算按钮,lblResult 是输出结果的标签。