错误:"<="标记之前的预期主表达式
error: expected primary-expression before '<=' token
下面是一个提示用户输入数字的简单程序。根据输入的值为用户分配一个不及格、及格、优秀或优异等级:
#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
周围添加括号,这会产生更多错误。
我哪里错了?
应该是
你的分数>30&;你的分数<40
假设每个条件都有一个真值或假值。在您的代码中(<=40)不是一个实际的布尔表达式。您必须操作
相关文章:
- (C++)分析树以计算返回错误值的简单算术表达式
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 提升精神:解析布尔表达式并简化为规范范式
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 呼叫运营商<<临时
- 使用正则表达式regex_search在字符串中查找字符串
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 概念中的cv限定符需要表达式参数列表
- 为什么constexpr的性能比正常表达式差
- 对于结构,表达式必须是可修改的ivalue
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 当一个值是非常量但用常量表达式初始化时使用constexpr
- 将fold表达式与std::一起用于两个元组
- <<操作员在下面的行中工作
- 断言中的Fold表达式在某些计算机上编译,但在其他计算机上不编译
- 标记 '","' 之前的预期主表达式
- gcc和clang在表达式是否为常量求值的问题上存在分歧
- 如何计算具有指定类型的表达式的相对精度和绝对精度
- 1<<31产生误差;'<<'表达式未定义”;