Ниже приведена простая программа, которая предлагает пользователю ввести номер. Пользователю присваивается оценка «Неудача», «Проход», «Заслуга» или «Отличительный знак» на основании введенного значения:
#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
, что приводило к большему количеству ошибок.
Куда я иду не так?