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

Compiling error, unresolved external error

本文关键字:错误 外部 编译 未解决      更新时间:2023-10-16

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

错误1错误LNK2019:无法解析的外部符号"int __cdecl findlow (int &,int &,int &,int &,int &)"(?findLowest@@YAHAAH0000@Z)在函数"void __cdecl calaverage (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;
}

什么可能导致错误,我该如何修复它?

问题是:

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

vs。:

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

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

相关文章: