我收到多条关于 LNK2019 的消息:未解析的外部符号

I am getting multiple messages referring to LNK2019: unresolved external symbol

我收到多条消息提到

LNK2019: unresolved external symbol "int_cdecl findLowest(int,int)"

在 function_main 中引用。每当我尝试编译我的程序时,这些消息中的 4 个弹出操作。我不知道如何解决这个问题,否则我不会寻求帮助。

#include <iostream>
using namespace std;
// This program calculates the average of the inputed temperatures and finds the highest and lowest
// 
int main()
{
    int numOfTemp;
    int temp[50];
    int pos;

    double findAverage(int, int);
    int findLowest(int, int);
    int findHighest(int, int);

    cout << "Please input the number of temperatures to be read (no more than 50)" << endl;
    cin >> numOfTemp;

    for (pos = 1; pos <= numOfTemp; pos++)
    {
        cout << "Input temperature " << pos << ":" << endl;
        cin >> temp[pos];
    }

    cout << "The average temperature is " << findAverage(temp[pos], numOfTemp) << endl;
    cout << "The lowest temperature is " << findLowest(temp[pos], numOfTemp) << endl;
    cout << "The highest temperature is " << findHighest(temp[pos], numOfTemp) << endl;//calls function   
}

double findAverage(int table[], int num)
{
    for (int i = 0; i < num; i++)
    {
        int sum = 0;
        sum += table[i];

        return (sum / num); // calculates the average
    }    
}

int findLowest(int table[], int num)
{
    float lowest;    
    lowest = table[0]; // make first element the lowest price 

    for (int count = 0; count < num; count++)
        if (lowest > table[count])
            lowest = table[count];
        return lowest;
}

// This function returns the highest price in the array 
int findHighest(int table[], int num)
{
    float highest;    
    highest = table[0]; // make first element the highest price 

    for (int count = 0; count < num; count++)
        if (highest < table[count])
            highest = table[count];    
    return highest;
}

在C++中,函数需要在使用前声明。您可以将 findAveragefindLowestfindHighest 的函数体放在 main 之上,或者使用前向声明。

编辑:确保你正确地声明了你的函数类型!正如我的评论所说,您声明并尝试调用

double findAverage(int, int)

但只定义

double findAverage(int[], int)

这将导致链接阶段失败,因为它找不到您对前者的定义。