使用MS Visual Studio 2019 C ++的Codeforce上的编译错误

#include <iostream>

using namespace std;

int main() { //Main Function

int w;
cout << "enter the weight of the watermelon: ";
cin >> w;

if (w <= 1 or w >= 100) {
cout << "error";
}

else {
if (w % 2 == 0) {
cout << "YES";
}
else {
cout << "NO";
}
}
return 0;

编译错误:

 syntax error: missing ')' before identifier 'or'
 error C2065: 'or': undeclared identifier
 error C2146: syntax error: missing ';' before identifier 'w'
 error C2059: syntax error: ')'
 error C2059: syntax error: ';'
 error C2059: syntax error: 'else'
 error C2143: syntax error: missing ';' before '{'
 error C2447: '{': missing function header (old-style formal list?)
 error C2059: syntax error: 'return'
 error C2059: syntax error: '}'
 error C2143: syntax error: missing ';' before '}'
评论
  • 情流感
    情流感 回复

    There is no or native operator in C++ ... unless you would define it. Use the logical || instead.

    #include <iostream>
    
    using namespace std;
    
    int main() { //Main Function
        int w;
        cout << "enter the weight of the watermelon: ";
        cin >> w;
    
        if (w <= 1 || w >= 100) { //use the logical or ||
            cout << "error";
        }
        else
        {
            if (w % 2 == 0) {
                cout << "YES";
            }
            else {
                cout << "NO";
            }
        }
        return 0;
    }