哪里不对?????

lyh306 2025-10-19 9:03:00 2025-10-19 9:05:27 6

#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; if (a == G) cout << "Hello,my master!I'm Xiaoluo."; else if (a == N) cout << "I'm Xiaoluo."; else if (a == S) cout << "Two tigers Two tigers,running so fast..."; else if (a == B && a == Q) cout << "Bye bye!"; else cout << "Sorry..."; return 0; }

{{ vote && vote.total.up }}

共 4 条回复

lyh306

@wc02222谢谢

lyh306
wc02222

干吗用int类型,这是字符串,要用char类型

int a;
cin >> a;

这错了

更正:

char a;
cin>>a;

还有两处错误:

一,字符串等于要在要用单引号

二,最后一个else if语句中不应该用&&,这是并且的意思,要用||这个才是或者

wc02222
#include <bits/stdc++.h>
using namespace std;
int main() {
    char a;
    cin >> a;
    if (a == 'G')
        cout << "Hello,my master!" << endl << "I'm Xiaoluo.";
    else if (a == 'N')
        cout << "I'm Xiaoluo.";
    else if (a == 'S')
        cout << "Two tigers Two tigers,running so fast...";
    else if (a == 'B' || a == 'Q')
        cout << "Bye bye!";
    else
        cout << "Sorry...";
    return 0;
}

已将你的代码更正