2012-02-21 12 views
1

以下は、番号の入力を促す簡単なプログラムです。ユーザは、失敗通過割り当てられ、メリットや区別グレード入力された値に基づいて:私はきエラー: '<='トークンの前に期待される一次式

main.cpp|21|error: expected primary-expression before '<=' token main.cpp|25|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; 
} 

は上記のコードをコンパイルしようとすると、次のエラーを生成します>30 && <=40>41 && <=50の前後にかっこを追加しようとしましたが、これによりエラーが増えました。

どこが間違っていますか?

答えて

4

yourScore>30 && yourScore<=40

は、各条件が真または偽の値を占めていることを想像しなければなりません。あなたのコード(< = 40)の実際のブール式ではありません。あなたはオペランドを持っている必要があります

+0

完璧、よろしくお願いします。 – unpossible

関連する問題