if语句中的错误

时间:2017-02-08 07:39:35

标签: if-statement

我尝试运行此代码,但问题是 - 因为我是初学者 - 我不知道如何在一个if语句中放置几个​​条件以及为什么if行和其他linke有错误。你能告诉我哪里出错了吗?谢谢

#include <iostream>
using namespace std;
int main(){

double AVG;
cout<< "please write in average\n";
cin>> AVG;
if ((AVG >60) && (AVG >=90))----------expected identifier
    cout<< "pass with grade of " << AVG ;
    cout << "\n" << "A star!\n";
else----------------------------------expected expression
    cout << "fail with grade of " << AVG << "\n";
cout<< "good luck with your smester !\n";

}

2 个答案:

答案 0 :(得分:0)

这可能会对您有帮助,而且无需添加(AVG >60) && (AVG >=90),就好像AVG>=90然后AVG >60已经为真。

#include <iostream>
using namespace std;
int main(){

    double AVG;
    cout<< "please write in average\n";
    cin>> AVG;
    if (AVG >=90)
    {
        cout<< "pass with grade of " << AVG ;
        cout << "\n" << "A star!\n";
    }
    else
    {  
        cout << "fail with grade of " << AVG << "\n";
        cout<< "good luck with your smester !\n";
    } 
    return 0;
}

答案 1 :(得分:0)

如果您使用多个语句,请使用括号,并使用int main(),然后需要返回一个值。

更新代码

syncronized

希望这有帮助