"Undefined reference to"

Im completely lost here I have no idea what it is asking for

ERROR IN COMPILER :

undefined reference to `PrintAll(std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, double*, double*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, int)'








//create function prototypes
void GetNames(string[],int);
void GetScores(double[],int);
double* GetAverage(double**, int);
void PrintAll(string[],double[],double*,string[],int);
int main()
{
char choice;
do{
//declare variables and knowns
int people;
double* average;
cout<<"In this program the data from a contest will be organized."<<endl;
cout<<"How many people were involved in the contest ?:";
cin>>people;
cout<<endl;
//create the dynamic arrays
string* names = new string[people];
double* scores = new double[people];
string above_below [people];
//fill the arrays
GetNames(names,people);
GetScores(scores,people);
//create a new pointer
double **ptr;
ptr = &scores;
//find the average
average = GetAverage(ptr,people);
//checks if scores are below or above average
for(int i = 0; i<people;i++)
{
if(scores[i]<*average)
{
above_below[i]="Below Average";
}
else if(scores[i]>*average)
{
above_below[i]="Above Average";
}
else
cout<<endl;
}
//print the results
PrintAll(names,scores,average,above_below,people);
do
{
cout<<"Do you want to go again ?(y/n):";
cin>>choice;
cout<<endl;
}while(choice!='y');
}while(choice=='y');
system("pause");
return 0;
}
//function used to get names
void GetNames(string names[],int people)
{
for(int i = 0; i<people;i++)
{
cout<<"Enter the name of contestant "<<" #"<<i+1<<" :";
cin.ignore('\n');
cin.clear();
cin>>names[i];
cout<<endl;
}

}
//function used to get the scores
void GetScores(double scores[],int people)
{
cout<<"The scores will have to be from 0 to 100"<<endl;
for(int i = 0;i<people;i++)
{
do
{
cout<<"Enter the scores of contestant "<<" #"<<i+1<<" :";
cin>>scores[i];
}while(scores[i]>=0&&scores[i]<=100);


cout<<endl;
}

}
//function used to get the average
double* GetAverage(double ptr[],int people)
{
//declare local variables
double sum = 0;
double avg;

//change people variable into a double to get an accurate value for avg
for(int i = 0; i<people; i++)
{
sum = ptr[i]+sum;
}
avg = sum/people;
double* avg1;
avg1 = &avg;
return avg1;

}

//function that will print all
void PrintAll(string names[],double scores[],double average,string
above_below[],int people)
{
cout<<"Average :"<<fixed<<setprecision(2)<<average<<endl;
cout<<"Names"<<right<<setw(30);
cout<<"Scores"<<right<<setw(30);
cout<<"Above/Below"<<endl;
cout<<endl;
for(int i = 0; i<people;i++)
{
cout<<names[i]<<right<<setw(30)<<scores[i]<<right<<setw(30)
<<above_below[i]<<endl;

}
delete names;
delete scores;


}
please wrap your code in [.code][./code] brackets (without the .) so it's easier to read.
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//create function prototypes
void GetNames(string[],int);
void GetScores(double[],int);
double* GetAverage(double**, int);
void PrintAll(string[],double[],double*,string[],int);
int main()
{
char choice;
do{
//declare variables and knowns
int people;
double* average;
cout<<"In this program the data from a contest will be organized."<<endl;
cout<<"How many people were involved in the contest ?:";
cin>>people;
cout<<endl;
//create the dynamic arrays
string* names = new string[people];
double* scores = new double[people];
string above_below [people];
//fill the arrays
GetNames(names,people);
GetScores(scores,people);
//create a new pointer
double **ptr;
ptr = &scores;
//find the average
average = GetAverage(ptr,people);
//checks if scores are below or above average
for(int i = 0; i<people;i++)
{
if(scores[i]<*average)
{
above_below[i]="Below Average";
}
else if(scores[i]>*average)
{
above_below[i]="Above Average";
}
else
cout<<endl;
}
//print the results
PrintAll(names,scores,average,above_below,people);
do
{
cout<<"Do you want to go again ?(y/n):";
cin>>choice;
cout<<endl;
}while(choice!='y');
}while(choice=='y');
system("pause");
return 0;
}
//function used to get names
void GetNames(string names[],int people)
{
for(int i = 0; i<people;i++)
{
cout<<"Enter the name of contestant "<<" #"<<i+1<<" :";
cin.ignore('\n');
cin.clear();
cin>>names[i];
cout<<endl;
}

}
//function used to get the scores
void GetScores(double scores[],int people)
{
cout<<"The scores will have to be from 0 to 100"<<endl;
for(int i = 0;i<people;i++)
{
do
{
cout<<"Enter the scores of contestant "<<" #"<<i+1<<" :";
cin>>scores[i];
}while(scores[i]>=0&&scores[i]<=100);


cout<<endl;
}

}
//function used to get the average
double* GetAverage(double ptr[],int people)
{
//declare local variables
double sum = 0;
double avg;

//change people variable into a double to get an accurate value for avg
for(int i = 0; i<people; i++)
{
sum = ptr[i]+sum;
}
avg = sum/people;
double* avg1;
avg1 = &avg;
return avg1;

}

//function that will print all
void PrintAll(string names[],double scores[],double average,string
above_below[],int people)
{
cout<<"Average :"<<fixed<<setprecision(2)<<average<<endl;
cout<<"Names"<<right<<setw(30);
cout<<"Scores"<<right<<setw(30);
cout<<"Above/Below"<<endl;
cout<<endl;
for(int i = 0; i<people;i++)
{
cout<<names[i]<<right<<setw(30)<<scores[i]<<right<<setw(30)
<<above_below[i]<<endl;

}
delete names;
delete scores;


}


Your compiler already told you where the issue is : It's where you call/define
void PrintAll(string[],double[],double*,string[],int);

your definition of the function and the function itself has 2 different sets of arguments. Your compiler is saying that the function your calling isn't defined because of this.
Last edited on
so what would I have to do?
"undefined reference" means you declared that the function exists but you never defined it.
void PrintAll(string[],double[],double*,string[],int);

and

1
2
3
4
5
void PrintAll(string names[],double scores[],double average,string
above_below[],int people)
{
...
}


should have matching arguments.

try changing the definition to

1
2
void PrintAll(string names[],double scores[],double average,string
above_below[],int people);
so what would i have to change?
Last edited on
@Strifer, roger911 posted at the same time as you and you missed his post.
Topic archived. No new replies allowed.