1
下面是一个提示用户输入数字的简单程序。用户被分配一个失败,传球,优点或区别等级根据所输入的值:错误:'<='令牌之前预期的主表达式
#include <iostream>
using namespace std;
// 0-30 Fail
// 31-40 Pass
// 41-50 Merit
// 51 and over Distinction
int main()
{
int yourScore;
cout << "Please enter your score: " << endl;
cin >> yourScore;
if (yourScore <=30)
{
cout << "Your grade is fail. Better luck next time." << endl;
}
else if (yourScore >30 && <=40)
{
cout << "Your grade is pass. Good." << endl;
}
else if (yourScore >41 && <=50)
{
cout << "Your grade is merit. Well done." << endl;
}
else
{
cout << "Your grade is distinction. Excellent." << endl;
}
return 0;
}
试图编译上述代码产生如下错误:
main.cpp|21|error: expected primary-expression before '<=' token
main.cpp|25|error: expected primary-expression before '<=' token
我已经尝试在>30 && <=40
和>41 && <=50
之间添加括号,这会产生更多错误。
我哪里错了?
完美,谢谢。 – unpossible 2012-02-21 11:57:26