Marwan
Marwan

Reputation: 1

How to avoid " undefined reference to ... ' " when using arrays and functions?

I'm learning how to use arrays as funtion arguments by making a program that does the following:

  1. Gets four test scores from the user and stores it in an array
  2. Calculates the sum of the scores in the array
  3. subtracts the lowest test score from the sum, and gives an adjusted sum
  4. Calculates the average from the adjusted sum, and prints out the average

I found this program in a book called "starting out with c++" I seem to have followed the source code it provides to solve this problem but and error occurs and I don't understand where the problem is.

Here is my incomplete source code: ( I am using code blocks )

The error appears in line 20 :

undefined reference to 'GetTotal(double const*, int)'

#include <iostream>
#include <iomanip>
using namespace std;

void GetScores(double[], int);
double GetTotal(const double[], int);
double GetLowest(const double[], int);

int main()
{
    const int SIZE = 4;
    double scOres[SIZE],//array holds scores
        total, // to store total test scores
        lowestScore, // to store lowest test score
        average;// to store average value

    GetScores(scOres , SIZE); //gets test scores from user
    GetTotal(scOres , SIZE); //sums up test scores
    GetLowest(scOres , SIZE); //gets lowest score

    return 0;
}

void GetScores(double scores[],int size)
{
    for (int index = 0; index < size; index++)
    {
        cout << "Enter test score " << index + 1 << ":" ;
        cin >> scores[index];
    }
}

so how can I solve this problem?

Upvotes: 0

Views: 2251

Answers (1)

Gunther Van Butsele
Gunther Van Butsele

Reputation: 524

double GetTotal(const double[], int);
double GetLowest(const double[], int);

These functions don't have a body, they are not defined anywhere. You'll need the source code of those two functions.

Upvotes: 6

Related Questions