修复 C++ 项目中未找到标识符的错误

时间:2021-04-08 04:42:07

标签: c++ project

我的代码问题与我的函数有关。此代码是会议中足球运动员的一个非常基本的 UI 菜单。当我对代码进行重大更改时,问题就出现了。最初,我的添加、搜索、更新和删除功能都保存在一个唯一的头文件“player.h”中,然后将其包含在我的 main.cpp 文件中。我遇到的错误是当我使用这些函数并将它们移动到我的 int main() 下方时。我收到所有 4 个函数的标识符未找到错误。请指教

#include <iostream>
using namespace std;

int const SIZE = 20;
int playerCount = 0;
int option;
string names[SIZE];
int ID[SIZE];
string schools[SIZE];
string nationality[SIZE];

int main()
{

cout << "Welcome to Ultimate Soccer Database" << endl;
cout << endl << "This is the complete database of all College in the WHAC." << endl;
cout << endl << "Currently we only have players from LTU" << endl;

while (1)
{
    cout << "**********************************" << endl;
    cout << "1. Add Player" << endl;
    cout << "2. Search Player" << endl;
    cout << "3. Update Player" << endl;
    cout << "4. Delete Player" << endl;
    cout << "5. Exit" << endl;
    cout << "**********************************" << endl;
    cout << "Enter your option : ";
    cin >> option;
    cout << "\n";

    if (option == 1)
    {
        add();

    }

    else if (option == 2)
    {
        search();
    }

    else if (option == 3)
    {
        update();

    }

    else if (option == 4)
    {
        delete_player();

    }

    else if (option == 5)
    {
        break;
    }
    cout << "\n\n";
}

return 0;
}

void add()
{

std::cout << "--------> Enter name : ";
std::cin >> names[playerCount];
std::cout << "--------> Enter ID : ";
std::cin >> ID[playerCount];
std::cout << "--------> Enter school : ";
std::cin >> schools[playerCount];
std::cout << "--------> Enter nationality : ";
std::cin >> nationality[playerCount];
playerCount++;
}

void search()
{
int id;
cout << "Enter ID : ";
cin >> id;
bool found = false;

for (int i = 0; i < playerCount; i++)
{
    if (ID[i] == id)
    {
        cout << "Player Found" << endl;
        cout << "--------> ID : " << ID[i] <<
            "\n--------> Name : " << names[i] <<
            "\n--------> School : " << schools[i] <<
            "\n--------> Nationality : " << nationality[i];
        found = true;
        break;
    }
}if (!found)
{
    cout << "-------->Player not found" << endl;
}

}

void update()
{


int id;
string school;
cout << "Enter ID : ";
cin >> id;
cout << "Enter new school : ";
cin >> school;
bool found = false;

for (int i = 0; i < playerCount; i++)
{
    if (ID[i] == id)
    {
        schools[i] = school;
        cout << "--------> Player school updated" << endl;
        found = true;
        break;
    }
}

if (!found)
{
    cout << "--------> Player not found" << endl;
}
}


void delete_player()
{

int id;
cout << "Enter ID : ";
cin >> id;
bool found = false;

for (int i = 0; i < playerCount; i++)
{
    if (ID[i] == id)
    {
        for (int j = i; j < playerCount - 1; j++)
        {
            ID[j] = ID[j + 1];
            names[j] = names[j + 1];
            schools[j] = schools[j + 1];
            nationality[j] = nationality[j + 1];
        }
        playerCount--;
        cout << "--------> Player deleted" << endl;
        found = true;
        break;
    }
}

if (!found)
{
    cout << "--------> Player not found" << endl;
}
}

Link to my error messages

0 个答案:

没有答案
相关问题