Help with Error LNK2019

Dear fellow Programmers,

I have been having this problem with this program for the past few days, I can't seem figure out what I did wrong to make it act this way. I have a feeling it has to do with inputing an array in a function but I am not sure. Any and all help would be appreciated.

I was able to get the program to work without functions but I am required to use them for this asignment.

I would preferabley like to have this answered before 26 September 2011 11:59 central time.

Thank you for your time.

LL
________________________________________________________________________________
Error:
1>------ Build started: Project: Lowest Score Drop, Configuration: Debug Win32 ------
1> Lowest Score Drop.cpp
1>Lowest Score Drop.obj : error LNK2019: unresolved external symbol "void __cdecl calcAverage(float,float,float,float)" (?calcAverage@@YAXMMMM@Z) referenced in function _main
1>Lowest Score Drop.obj : error LNK2019: unresolved external symbol "void __cdecl getScores(float,int)" (?getScores@@YAXMH@Z) referenced in function _main
1>Lowest Score Drop.obj : error LNK2019: unresolved external symbol "float __cdecl findLowest(float,float,float)" (?findLowest@@YAMMMM@Z) referenced in function "void __cdecl calcAverage(float,float,float * const,float)" (?calcAverage@@YAXMMQAMM@Z)
1>K:\School\Classes\CIS 2541\Lowest Score Drop\Debug\Lowest Score Drop.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


--------------------------------------------------------------------------------
Code
________________________________________________________________________________

#include<iostream>


using namespace std;


// Function getScores()
void getScores(float, int);


// Function calcAverage()
void calcAverage(float, float, float,float);


// Function findLowest()
float findLowest(float, float, float);


int main()
{
float scores[6] = {0.0};
float total = 0,
avrg = 0,
low = 101;

for (int i = 0; i != 5; i++)
{
getScores(scores[i], i);
}

calcAverage(total, avrg, scores[6], low);

// End use of functions, give output

cout << endl;
cout << "Your scores are as followed: ";

for(int i = 0; i != 5; i++)
{
cout << scores[i] << ", ";
}

cout << endl;

cout << "Your lowest score was: " << low << endl;

cout << "Your total with the lowest score dropped is: " << total << endl;

cout << "Your average score is: " << avrg << endl;

system("pause");
return 0;
}


void getScores(float scores[6], int i)
{
do
{
cout << "Enter score between 1 and 100: ";
cin >> scores[i];
}while(scores[i] < 1 || scores[i] > 100);
}


void calcAverage(float total, float average, float scores[6], float low)
{
low = findLowest(total, scores[6], low);

for(int i = 0; i != 5; i++)
{
total = total + scores[i];
}

total = total - low;

average = total / 4;
}


float findLowest(float total, float scores[6], float low)
{
for(int i = 0; i != 5; i++)
{
if(low > scores[i])
{
low = scores[i];
}
}

return low;
}
Last edited on
closed account (zb0S216C)
Your prototypes don't match their definitions. More specifically, the parameter lists don't match the definitions. Each prototype function parameter list accepts an array as an argument. For this to work, the parameter that accepts the array must be a pointer, just like this example:

1
2
3
4
5
6
7
8
9
10
11
void Function( int[6] ); // int[] is the same as int*

int main( )
{
    // ...
}

void Function( int Array[6] )
{
    // ...
}

Since you know the size of each array (judging by your code), I would recommend that you pass the array by reference, like this:

1
2
3
4
5
6
7
8
9
10
11
void Function( int( & )[6] );

int main( )
{
    // ...
}

void Function( int( &Array )[6] )
{
    // ...
}


Wazzak
Last edited on
Topic archived. No new replies allowed.