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