尝试在console
中创建一个VSL studio 2012
应用程序,根据用户输入的温度输出有关穿戴的建议,我遇到了错误
“无效的表达术语”
我在此代码中的所有其他if语句。我不知道我在这里做错了什么。
如果有人能指出我正在解决这个问题的方向,那就太棒了! 谢谢
if (temp <= 40)
{
Console.WriteLine(" It is very cold. Put on a heavy coat.");
}
else if (temp > 40 && <= 60)
{
Console.WriteLine("It is cold. Put on a coat.");
}
else if (temp > 60 && <= 70)
{
Console.WriteLine("The temperature is cool. Put on a light jacket.");
}
else if (temp > 70 && <= 80)
{
Console.WriteLine("The temperature is pleasent. You can wear anything you like");
}
else if (temp > 80 && <= 90)
{
Console.WriteLine(" The temperautre is warm, you can wear short sleeves.");
}
else (temp > 90)
{
Console.WriteLine("It is hot. You can wear shorts today.");
}
答案 0 :(得分:5)
这是无效的语法:
else if (temp > 40 && <= 60)
你需要这样做:
else if (temp > 40 && temp <= 60)
答案 1 :(得分:2)
您写了无效的表达式:
(temp > 40 && <= 60)
格式正确:
(temp > 40 && temp <= 60)
请更正所有无效的表达方式。
答案 2 :(得分:0)
代替
else (temp > 90)
使用
else if (temp > 90)
所以,你的整个代码应该是:
if (temp <= 40)
{
Console.WriteLine(" It is very cold. Put on a heavy coat.");
}
else if (temp > 40 && temp <= 60)
{
Console.WriteLine("It is cold. Put on a coat.");
}
else if (temp > 60 && temp <= 70)
{
Console.WriteLine("The temperature is cool. Put on a light jacket.");
}
else if (temp > 70 && temp <= 80)
{
Console.WriteLine("The temperature is pleasent. You can wear anything you like");
}
else if (temp > 80 && temp <= 90)
{
Console.WriteLine(" The temperautre is warm, you can wear short sleeves.");
}
else if (temp > 90)
{
Console.WriteLine("It is hot. You can wear shorts today.");
}