C++可以多次用else if问题

2025-03-24 21:00:06
推荐回答(4个)
回答1:

if (weight < standard_weight * 0.6)
cout<<"体重评价:严重营养不良"<else if (weight < standard_weight * 0.8)
cout<<"体重评价:中度营养不良"<else if (weight < standard_weight * 0.9)
cout<<"体重评价:轻度营养不良"<else if (weight < standard_weight * 1.1)
cout<<"体重评价:正常"<else
cout<<"体重评价:肥胖"<

回答2:

standard_weight * 0.6 <= weight < standard_weight * 0.8改成
standard_weight * 0.6 <= weight && weight < standard_weight * 0.8
其他的else if也要改,不然计算机不能识别条件的意思。

回答3:

if(b>0)
n++;
sum1+=b;
语义出错
如果if语句后面没有做语言操作符{}的话,默认下一条语句作为表达式为真的执行语句
所以
if(b>0)
{n++;
sum1+=b;
}才是正确的
求采纳为满意回答。

回答4:

你输入standard_weight的值试试