需要有关使用C ++进入函数的帮助

时间:2016-12-29 06:56:29

标签: c++

以下是我的代码示例:

//Function Declarations
void askChampSearch(string&, string&);

void displayChampDetail(string);

int main()
{
string searchedChamp;
string aboutUser;

cout << "**********YOU'RE GOING TO WANT TO MAKE YOUR PROMPT FULL SCREEN**********" << endl;
cout << "Welcome to my LEAGUE OF LEGENDS info guide!" << endl;
cout << "You can search any champion in League of Legends, and all" << endl;
cout << "of that champions information will be displayed.The information" << endl;
cout << "that will be displayed is: Abilites, Champion Lore, About The Campion, Best Build, and the Champions Wiki Page!" << endl;
cout << endl;

askChampSearch(aboutUser, searchedChamp);
displayChampDetail(searchedChamp);

return 0;
}

//Function Definitions
void askChampSearch(string& UserName, string& searchedChamp){
cout << "Thank you for trying out my program! I really appreciate it! What is your name? (Don't worry, your name isn't stored) ";
    cin >> UserName;
    cout << "Hi " << UserName << ", nice to meet you!" << endl;
    cout << endl;

    cout << "What League of Legends champion would you like to search? ";
    cin >> searchedChamp;
    cout << "The champion that you have searched for was " << searchedChamp << "!";
}

void displayChampDetail(string searchedChamp) {
if (searchedChamp == Ahri) {
    cout << "Ahri is a nine-tailed fox who is a whore" << endl;
    cout << "If Ahri hits you with a charm, you are fucked" << endl;
}


}

我遇到的问题是在我的程序离开第一个空白之后:

void askChampSearch(string& UserName, string& searchedChamp){
cout << "Thank you for trying out my program! I really appreciate it! What is your name? (Don't worry, your name isn't stored) ";
    cin >> UserName;
    cout << "Hi " << UserName << ", nice to meet you!" << endl;
    cout << endl;

    cout << "What League of Legends champion would you like to search? ";
    cin >> searchedChamp;
    cout << "The champion that you have searched for was " << searchedChamp << "!";
}

它不会进入下一个!例如。如果用户键入名称Ahri,它应该显示我所做的,但它说我需要定义Ahri。如何在第二个Void中定义Ahri。这是我的第二个虚空的代码:

void displayChampDetail(string searchedChamp) {
if (searchedChamp == Ahri) {
    cout << "Ahri is a nine-tailed fox" << endl;
    cout << "If Ahri hits you with a charm, you are dead" << endl;
}
}

我想要做的是,如果用户输入名称Ahri,那就是我提供的信息。

我得到的错误代码是标识符“Ahri”未定义。

1 个答案:

答案 0 :(得分:1)

searchedChamp == "Ahri"  

这是一个字符串。其他明智的编译器试图找到一个名为“Ahri”的变量,它找不到它,所以它要求你定义它。