编译错误,未解决的外部错误

时间:2014-03-27 17:23:21

标签: c++ visual-c++

我尝试编写一个程序来删除5个输入中的最低点并计算剩余4个的平均值,但由于我收到的错误,我无法编译。错误是:

错误1错误LNK2019:未解析的外部符号" int __cdecl findLowest(int&,int&,int&,int&,int&)"函数中引用了(?findLowest @@ YAHAAH0000 @ Z)" void __cdecl calcAverage(double&)" (?calcAverage @@ YAXAAN @ Z)

我不知道它意味着什么或如何解决它。我的代码如下:

#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;
}

可能导致错误的原因以及我该如何解决?

1 个答案:

答案 0 :(得分:2)

问题在于:

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

VS。这样:

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

定义中还有一个参数而不是声明。在我看来,lowest应该只是一个局部变量而不是一个参数。