Not understanding why I'm getting error

So I keep getting " undefined reference to 'lowestStudentGPA(std::string, double)' ". I really can't see what's the problem here. The other functions are commented out since I am testing to make sure lowestStudentGPA works before continuing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  #include <iostream>
#include <fstream>
#include <string>
using namespace std;
void lowestStudentGPA(string, double);
void highestStudentGPA(string, double);
void averageStudentGPA(string, double);

//Variables
const int arraySize = 15;
int i = 0;
double gpa[arraySize];
string name[arraySize];

int main()
{
    ifstream inputFile;
    inputFile.open("GPA.txt");

    cout << "Reading data from the file..\n";

    while (i < arraySize && inputFile >> name[i] >> gpa[i])
        i++;
    inputFile.close();

    /*for (i = 0;i < arraySize;i++)*/

        lowestStudentGPA(name[i], gpa[i]);

    return 0;
}
void lowestStudentGPA(string name[], double gpa[])
{
int i;
double lowestGPA;
string lowestStudent;
lowestGPA = gpa[0];
for (i = 1; i < arraySize; i++)
{
    if (gpa[i] < lowestGPA)
    {
        lowestGPA = gpa[i];
        lowestStudent = name[i];
    }
    cout << lowestStudent << "\t\t" << lowestGPA << endl;
}
}
/*void highestStudentGPA(string name, double gpa)
{

}
void averageStudentGPA(string name, double gpa)
{

}*/
Your declarations have different parameters to your definitions
1
2
void lowestStudentGPA(string, double);
void lowestStudentGPA(string name[], double gpa[])
Undefined reference means it can't find the definition of the function mentioned.

On line 5 you have declared a function named lowestStudentGPA with two parameters, the first having type std::string and the second having type double.

On line 32 you have defined a function named lowestStudentGPA with two parameters, the first having type std::string* and the second having type double*.

Note that the types are different and therefore they are two different functions.
Oh, thank you so much to the both of you! I thought using prototypes would work, how I was doing it.
Topic archived. No new replies allowed.