undefined reference to function

Hello, I'm having trouble processing and displaying a sorted array of random numbers. Any pointers would be of great help. I try running it and I get an error stating that there's an undefined reference both of my sort functions and I'm getting id returned 1 exit status. Can you tell me whats wrong here? thanks

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <iomanip>
using namespace std;

double *getRandomTestScores(int);
double *getLowestTestScore(double *, int);
double *getHighestTestScore(double *, int);
double calcAverage(double *, int, double);
double calcStandardDeviation(double *, double);
void sortTestScores(double [] , int);
void showSortTestScores(double [] , int);
void showRandomTestScores(double [], int);
void showCalculations(double *, double *, double, double);
const int SIZE = 30;

int main()
{
double *scores = 0; // Points to the test scores
double *lowestTestScore;
double *highestTestScore;
double standardDeviation;
double total = 0.0;
double average;
int count;

// Get an array of 30 random test scores.
scores = getRandomTestScores(SIZE);

showRandomTestScores(scores, SIZE);

lowestTestScore = getLowestTestScore(scores, SIZE);

highestTestScore = getHighestTestScore(scores, SIZE);

average = calcAverage(scores, SIZE, total);

standardDeviation = calcStandardDeviation(scores, average);

showCalculations(lowestTestScore, highestTestScore, average, standardDeviation);


sortTestScores(scores, SIZE);

showSortTestScores(scores, SIZE);

delete [] scores;
scores = 0;
return 0;
}

double *getRandomTestScores(int num)
{
const int MIN_SCORE = 0;
const int MAX_SCORE = 100;
double *arrTestScores = 0; // Array that holds test scores

if (num <= 0)
return 0;

arrTestScores = new double[num];

srand(time(0));

for (int count = 0; count < num; count++)
arrTestScores[count] = (rand() % (MAX_SCORE - MIN_SCORE + 1)) + MIN_SCORE;

return arrTestScores;
}

double *getLowestTestScore(double scores[], int size)
{
double *lowest;

lowest = &scores[0];

for (int count = 1; count < size; count++)
{
if (scores[count] < *lowest)
lowest = &scores[count];
}
return lowest;
}

double *getHighestTestScore(double scores[], int size)
{
double *highest;

highest = &scores[0];

for (int count = 1; count < size; count++)
{
if (scores[count] > *highest)
highest = &scores[count];
}
return highest;
}

double calcAverage(double scores[], int size, double total)
{
double avg;
for (int count = 0; count < SIZE; count++)
total += scores[count];
avg = total / size;
return avg;
}

double calcStandardDeviation(double scores[], double average)
{
double stanDev;
double temp;
for (int s = 0; s < SIZE; s++)
temp += pow((scores[s] - average), 2);
stanDev = sqrt(temp /(SIZE - 1));
return stanDev;
}

void showRandomTestScores(double scores[], int size)
{
double total;
for (int count = 0; count < SIZE; count++)
{
cout << scores[count] << endl;
total += scores[count];
}
cout << "total: " << total << endl;

}

void showCalculations(double *lowestTestScore, double *highestTestScore, double average, double standardDeviation)
{
cout << "lowest: " << *lowestTestScore << endl;
cout << "highest: " << *highestTestScore << endl;
cout << "avg: " << average << endl;
cout << "standev: " << standardDeviation << endl;
}
void sortTestScores(double *scores[], int size)
{
int scanTests, minIndex;
double *minElem;

for (scanTests = 0; scanTests < (size - 1); scanTests++)
{
minIndex = scanTests;
minElem = scores[scanTests];
for (int index = scanTests + 1; index < size; index++)
{
if (*(scores[index]) < *minElem)
{
minElem = scores[index];
minIndex = index;
}
}
scores[minIndex] = scores[scanTests];
scores[scanTests] = minElem;
}
}
void showSortTestScores(double *scores[], int size)
{
for (int count = 0; count < size; count++)
cout << *(scores[count]) << " ";
cout << endl;
}
Last edited on
You have functions with wrong signatures.
Function 1.
1
2
3
4
5
6
void showSortTestScores(double *scores[], int size)
{
for (int count = 0; count < size; count++)
cout << *(scores[count]) << " ";
cout << endl;
}


The correct function is :
1
2
3
4
5
6
void showSortTestScores(double scores[], int size)
{
for (int count = 0; count < size; count++)
cout << scores[count] << " ";
cout << endl;
}


Function 2.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void sortTestScores(double *scores[], int size)
{
int scanTests, minIndex;
double *minElem;

for (scanTests = 0; scanTests < (size - 1); scanTests++)
{
minIndex = scanTests;
minElem = scores[scanTests];
for (int index = scanTests + 1; index < size; index++)
{
if (*(scores[index]) < *minElem)
{
minElem = scores[index];
minIndex = index;
}
}
scores[minIndex] = scores[scanTests];
scores[scanTests] = minElem;
}
}


The function should be :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void sortTestScores(double scores[], int size)
{
int scanTests, minIndex;
double minElem;

for (scanTests = 0; scanTests < (size - 1); scanTests++)
{
minIndex = scanTests;
minElem = scores[scanTests];
for (int index = scanTests + 1; index < size; index++)
{
if (scores[index] < minElem)
{
minElem = scores[index];
minIndex = index;
}
}
scores[minIndex] = scores[scanTests];
scores[scanTests] = minElem;
}
}
Thanks so much comaHelp! that worked and I can finally have some sleep.
Topic archived. No new replies allowed.