vendredi 28 avril 2017

Getting an error - "undefined reference to 'logOn(int, int &)'"

I am working on this program (below) and keep getting the "undefined reference to 'logOn(int, int &)'". It also does this when I am calling the functions for logOn, logOff, and search when they are called. My code is not 100% correct, but I am trying to figure out my error before I can move on with the rest of the project.

    #include <iostream>#include <iostream>

    int menu(int &);
    void logOn(int, int &);
    int getUserID(int &);
    int getLabNum(int &);
    int getStation(int &, int &);
    void logOff(int, int &);
    void search(int, int &);

    int main()
    {
        int userChoice = 0;
        menu(userChoice);
        int userID = 0;

        int lab[4][6];
        if (userChoice == 1)
        {
            logOn(lab[4][6], userID);
        }
        else if (userChoice == 2)
        {
            logOff(lab[4][6], userID);
        }
        else if (userChoice == 3)
        {
            search(lab[4][6], userID);
        }

        return 0;
    }

And here are the three functions:

    void logOn(int lab[4][6], int &userID)
    {
        int labNum, station = 0;

        getUserID(userID);
        getLabNum(labNum);
        getStation(station, labNum);

        int *lab_ptr = &labNum;
        int *station_ptr = &station;
        int *user_ptr = &userID;

        for (int i = 1; i < 5; i++)
        {
            std::cout << "Lab " << i << ": ";
            if (i == 1)
            {
                for (int j = 1; j < 6; j++)
                {
                    lab[*lab_ptr][*station_ptr] = {*user_ptr};
                }
            } 
        }
    }

    void logOff(int lab[4][6], int &userID)
    {
        std::cout << "Please enter your student ID: ";
        std::cin >> userID;
        std::cout << std::endl;
        for(int i = 1; i < 5; i++)
        {
            for(int j = 1; j < 7; j++)
            {
                if(lab[i][j] == userID)
                {
                    lab[i][j] = 0;
                }
            }
        }
    }

    void search(int lab[4][6], int &userID)
    {
std::cout << "Please enter the User ID you would like to find: ";
std::cin >> userID;

for(int i = 1; i < 5; i++)
{
    if (i == 1)
    {
        for(int j = 1; j < 6; j++)
        {
            if(lab[i][j] == userID)
            {
                std::cout << "This user is in lab " << i << " and at station " << j << std::endl;
                return;
            }
        }
    }
    etc....

I think it has something to do with the lab[4][6] in the headers, but I saw another program with it and it ran with no problem. Any help would be appreciated!

Aucun commentaire:

Enregistrer un commentaire