-2

I tried writing a program to drop the lowest of 5 inputs and calculate the average of the remaining 4, but I can't compile because of an error I am receiving. the error is:

Error 1 error LNK2019: unresolved external symbol "int __cdecl findLowest(int &,int &,int &,int &,int &)" (?findLowest@@YAHAAH0000@Z) referenced in function "void __cdecl calcAverage(double &)" (?calcAverage@@YAXAAN@Z)

I don't know what it means or how to fix it. My code is as follows:

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

void getScore(int &, int &, int &, int &,int &);
void calcAverage(double &);
int findLowest(int &, int &, int &, int &, int &);

int main()
{

    int test1 = 0, test2 = 0, test3 = 0, test4 = 0, test5 = 0;
    string response; 
    //double averge;


    getScore(test1, test2, test3, test4, test5);
    //calcAverage(averge);

    cout << "Are there any more test scores?" << endl;
    cin >> response;
    cout << endl;
    if (response == "yes")
    {
        //getScore(test1, test2, test3, test4, test5);
        //calcAverage(averge);
    }

    system("pause");
    return 0;
}


void getScore(int &num1, int &num2, int &num3, int &num4, int &num5)
{
    cout << "What was your score for the first test?" << endl;
    cin >> num1;
    cout << endl;
    if (num1 < 1 || num1 > 100)
    {
        cout<<"Scores must be between 1 and 100, re-enter the score" << endl;
        cin >> num1;
    }

    cout << "What was your score for the second test?" << endl;
    cin >> num2;
    cout << endl;
    if(num2 < 1 || num2 > 100)
    {
        cout<<"Scores must be between 1 and 100, re-enter the score" << endl;
        cin >> num1;
    }

    cout << "What was your score for the third test?" << endl;
    cin >> num3;
    cout << endl;
    if(num3 < 1 || num3 > 100)
    {
        cout<<"Scores must be between 1 and 100, re-enter the score" << endl;
        cin >> num1;
    }

    cout << "What was your score for the fourth test?" << endl;
    cin >> num4;
    cout << endl;
    if(num4 < 1 || num4 > 100)
    {
        cout<<"Scores must be between 1 and 100, re-enter the score" << endl;
        cin >> num1;
    }

    cout << "What was your score for the fifth test?" << endl;
    cin >> num5;
    cout << endl;
    if(num5 < 1 || num5 > 100)
    {
        cout<<"Scores must be between 1 and 100, re-enter the score" << endl;
        cin >> num1;
    }

    //return num1, num2, num3, num4, num5;
}


void calcAverage(double &average)
{
    int number1, number2, number3, number4, number5, lowest;

    lowest = findLowest(number1, number2, number3, number4, number5);

    cout << lowest << endl;

}
int findLowest(int &num1, int &num2, int &num3, int &num4, int &num5, int &lowest)
{

    lowest = num1;

    if (num2 < lowest)
    {
        lowest = num2;
        //return lowest;
    }
    else if (num3 < lowest)
    {
        lowest = num3;
        //return lowest;
    }
    else if (num4 < lowest)
    {
        lowest = num4;
        //return lowest;
    }
    else if (num5 < lowest)
    {
        lowest = num5;
        //return lowest;
    }
    return lowest;
}

What might be causing the error and how might I fix it?

1 Answers1

2

The problem is this:

int findLowest(int &, int &, int &, int &, int &);

vs. this:

int findLowest(int &num1, int &num2, int &num3, int &num4, int &num5, int &lowest)

You have one more argument in the definition than the declaration. It appears to me that lowest should simply be a local variable rather than a parameter.

Fred Larson
  • 60,987
  • 18
  • 112
  • 174