我对else if语句做错了什么

dst*_*num -2 c++ if-statement

该程序告诉我它需要一个带有else if语句的语句.我真的很新,而且在我上大学之前参加任何CS课程之前,我正在尝试学习c ++代码.提前致谢!

#include <iostream>
#include <string>
using namespace std;
string color;
string Blue;
string Green;
string Brown;

int age;
int main()
{
    cout << "what is the color of your eyes ? (use capitalization)" << endl << "colors to choose from are " << endl << "Blue" << endl << "Green" << endl << "Brown";
    cin >> color;

    if (color == Blue); {
        cout << "you are an intelligent person " << endl;
        system("pause");
    }
    else if (color == Green); {
        cout << " you are a peaceful person " << endl;
        system("pause");
    }
    else if (color == Brown); {
        cout << "you are a normal go get 'em person " << endl;
        system("pause");
    }


    cin.ignore();
    cin.get();
    return 0;

}
Run Code Online (Sandbox Code Playgroud)

Joh*_*son 11

你的问题是你在括号后面有分号.这个:

if (color == Blue); {
    cout << "you are an intelligent person " << endl;
    system("pause");
}
Run Code Online (Sandbox Code Playgroud)

应该是这个

                 No semi colon here
                  v
if (color == Blue) {
    cout << "you are an intelligent person " << endl;
    system("pause");
}
Run Code Online (Sandbox Code Playgroud)

对于其余的其他人来说也是如此

另外,正如其他人所提到的,你需要指明蓝色,绿色和棕色.要么这样做:

const string Blue = "Blue";
const string Green = "Green";
const string Brown = "Brown";
Run Code Online (Sandbox Code Playgroud)

或者如果你想:

 if (color == "Blue") {   //Note the ""
    cout << "you are an intelligent person " << endl;
    system("pause");
}
Run Code Online (Sandbox Code Playgroud)