我编写对成绩评级的代码,利用条件运算符,可是执行代码块部分却出现了问题,请指教!
编译错误提示:缺少“;”(在“{”的前面)
代码如下:
#include
#include
#include
using namespace std;
int main()
{
vector vec = { "E","D","C","B","A","A++" };
int grade;
string result;
cout << "请输入你的成绩:";
cin >> grade;
(grade < 0 || grade>100) ? {
cout << "该成绩不合法" << endl;
return -1;
}
: (grade < 60)
result = vec[0];
:
{
result = vec[(grade - 50) / 10];
if ((grade % 10) <= 3 && (grade % 10)>0)
result += '-';
else if ((grade % 10) >= 7)
result += '+';
}
cout << result << endl;
return 0;
}