如何解决在if-else语句“之前的预期基本表达式>标记”?
问题描述:
我试图让这个if-else语句确保一个数字是0和100之间做别的事情与它之前。如何解决在if-else语句“之前的预期基本表达式>标记”?
if (test1 < 0 || > 100) // I get the error here.
{
cout << "This score is good." << endl;
}
else
{
cout << endl << "ERROR: " << test1 << " is not a valid test score.";
return 1;
}
答
将其更改为
if (test1 > 0 && test1 < 100) (1-99 are = true)
- >它需要一个布尔结果。
答
呸,我不得不写TEST1两次。也弄错了操作员。
if (test1 >= 0 && test1 <= 100) // I get the error here.
{
cout << "This score is good." << endl;
}
else
{
cout << endl << "ERROR: " << test1 << " is not a valid test score.";
return 1;
}
答
有两个缺陷。第一个导致编译器错误的是条件
if (test1 < 0 || > 100) // I get the error here.
语法上写错了。应该有
if (test1 < 0 || test > 100)
第二个缺陷,它会好得多,如果测试具有无符号整型。在这种情况下,您可以简化条件
if (test > 100)
{
cout << "This score is good." << endl;
}
else
{
cout << endl << "ERROR: " << test1 << " is not a valid test score.";
return 1;
}
您是否确定不是指以下内容?
if (test <= 100)
{
cout << "This score is good." << endl;
}
else
{
cout << endl << "ERROR: " << test1 << " is not a valid test score.";
return 1;
}
'TEST1 100' – 101010 2014-10-02 06:11:35