Blader2themax10
Blader2themax10

Reputation: 23

Unresolved External Symbol - How to fix?

I'm pretty new to programming. I have run into this error that I can't figure out. You should be able to put in a score and it will use the information that is pre put in the array and tell you how many students got that grade.

The error msg I get is:

1>------ Build started: Project: Ch11_27, Configuration: Debug Win32 ------
1>Build started 4/4/2013 1:17:26 PM.
1>InitializeBuildStatus:
1>  Touching "Debug\Ch11_27.unsuccessfulbuild".
1>ClCompile:
1>  main.cpp
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl checkScore(int * const,int * const)" (?checkScore@@YAXQAH0@Z) referenced in function _main
1>F:\a School Stuff TJC Spring 2013\Intro Prog\C++ Projects\Ch11_27\Debug\Ch11_27.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.

Here is my code:

//Advanced27.cpp - displays the number of students
//earning a specific score
//Created/revised by <your name> on <current date>

#include <iostream>
using namespace std;

//Function Prototypes
void checkScore( int scores[], int storage[]);

int main()
{
    //declare array
    int scores[20] = {90, 54, 23, 75, 67, 89, 99, 100, 34, 99, 
                      97, 76, 73, 72, 56, 73, 72, 20, 86, 99};
    int storage[4] = {0};
    char answer = ' ';

    cout << "Do you want to check a grade? (Y/N): ";
    cin >> answer;
    answer = toupper(answer);

    while (answer = 'Y')
    {
        checkScore(scores, storage);

    cout << "Do you want to check a grade? (Y/N): ";
    cin >> answer;
    answer = toupper(answer);

    }
    system("pause");
    return 0;
}   //end of main function

//*****Function Defenitions*****
void checkGrade(int scores[], int storage[])
{
    int temp = 0;
    int earnedScore = 0;

    cout << "Enter a grade you want to check: ";
    cin >> earnedScore;

    for (int sub = 0; sub <= 20; sub +=1)
    {
        if (scores[sub] = earnedScore)
        {
            storage[temp] += 1;

        }
    }
}

Upvotes: 2

Views: 10633

Answers (4)

inetknght
inetknght

Reputation: 4439

It means that you declared the function to be named checkScore but you defined the function to be named checkGrade. Then when main() tries calling checkScore the compiler says "OK, that was declared above. I'll allow it even though I can't find it. It might be in a different library or source file.". Then it is the responsibility of the linker to find it. Since the linker finds checkGrade but doesn't find checkScore, the linker then throws the error saying undefined reference (main() references checkScore and not checkGrade).

Upvotes: 1

Geier
Geier

Reputation: 904

Your function checkGrade() below the main()-function should probably be called void checkScore( int scores[], int storage[])

Upvotes: 3

bash.d
bash.d

Reputation: 13207

It appears you have declared your function

void checkScore( int scores[], int storage[]);

but not actually defined it (giving it a function-body). Define your function like

void checkScore( int scores[], int storage[]){

}

to make this error go away.

Upvotes: 0

Joseph Mansfield
Joseph Mansfield

Reputation: 110658

The problem is that your function definition is named differently to your function declaration:

void checkScore( int scores[], int storage[]);
void checkGrade(int scores[], int storage[])

You need to pick one or the other. The compiler gets to your call to checkScore and sees that there is no definition for it. Changing the definition to be called checkScore would fix it.

Upvotes: 4

Related Questions