Good afternoon, i'm getting an error when I compile
"undefined reference to 'TestScores:theAverage(int *,int)"
I'm not sure what the compiler is telling me.
Any assistance is welcomed.
Art
header
// this is the header file for class TestScores
#ifndef TESTSCORES_H
#define TESTSCORES_H
//this idea with this class is to take an array, look at each element
//if element > 100 or element < 0, to throw an error back to the program
//if neither of these conditions is met then, the average is take and returned
//to the calling program
using namespace std;
const int ARRAYSIZE = 5; //constant for arraysize
class TestScores
{
private:
int holdelement;
double average;
public:
double theAverage(int[],int);
double getAverage()
{return average;}
class NegativeNumber //throw class for neg
{
private:
int value;
public:
NegativeNumber(int val)
{value = val;}
double getValue() const
{return value;}
};
class LargerThan //throw class for more than 100
{
private:
int value;
public:
LargerThan(int val)
{value = val;}
double getValue() const
{return value;}
};
};
#endif
cpp
//This is the cpp file for TestScores
#include "TestScores.h"
double TestScores::theAverage(int scores[],int size)
{
for(int count=0;count < size;count++)
{
if(scores[count]<0)//check for element < 0
{
throw NegativeNumber(scores[count]);//throw error if < 0
//this uses the value in the array and returns it to main
}
else if (scores[count] > 100)//check for element > 0
{
throw LargerThan(scores[count]);//throw error if > 0
//this uses the value in the array and returns it to main
}
else
{
holdelement += scores[count];//no error add it to holdval
average = (holdelement / 5.0);//keep a running average of holdval
}
return average;
}
}
main
//This is the main file for TestScores
#include <cstdlib>
#include <iostream>
#include "TestScores.h"
using namespace std;
int main(int argc, char *argv[])
{
int testscores[ARRAYSIZE];//set the size of the array
//Enter 5 integers
TestScores maintestscores;//define the object
cout << "Enter 5 integers: ";
cin >> testscores[0];
cin >> testscores[1];
cin >> testscores[2];
cin >> testscores[3];
cin >> testscores[4];
try
{
maintestscores.theAverage(testscores,ARRAYSIZE);//pass in the array
cout << "The average score is: "<< maintestscores.getAverage();
}
catch (TestScores::NegativeNumber e)
{
cout << "Error: " << e.getValue() << "is less than zero \n";
}
catch (TestScores::LargerThan e)
{
cout << "Error: " <<e.getValue() << "is greater than 100 \n";
}
cout << "End of program: ";
system("PAUSE");
return EXIT_SUCCESS;
}