c++ - LNK2019 - 未解析的外部符号 C++

标签 c++

我是 C++ 的新手,不知道去哪里找。我的程序似乎收到标记为 LNK2019 - 未解析的外部符号的错误。

确切消息是: “错误 LNK2019:未解析的外部符号“double_cdecl computeSTD(double*const, int)”(?computeSTD@@YANQANH@Z) 在 function_main 中引用)”

如果您能就我如何学习修复这些类型的错误提供任何建议,我将不胜感激!

下面提供的是我的源代码的拷贝。

#include <iostream>
#include <iomanip> // for Setprecision
#include <cmath> // for pow and sqrt

using namespace std;

//Prototypes
void programInformation();
void inputArrayValues (double array[], int SIZE, int &count);
void printListOriginal (double array[], int count);
void sortAscending (double array[], int count);
double computeAverage (double array[], int count);
double computeMedian (double array[], int count);
double computeSTD (double array[], int count);
void printCalculations (double average, double median, double std);

int main()
{
    // Declare Local Variables
    const int SIZE=30.0;
    double array[SIZE];
    double average;
    double median;
    double std;
    int count = 0;

    // Set Precision for Decimal Points
    cout << setprecision(1) << fixed <<showpoint;

    // Module Call for Program Infomation
    programInformation();

    // Module/Function Calls
    inputArrayValues (array, SIZE, count);
    printListOriginal (array, count);
    sortAscending (array, count);
    average = computeAverage (array, count);
    median = computeMedian (array, count);
    std = computeSTD (array, count);
    printCalculations (average, median, std);
    return 0;
}

//Module: programInformation
//Description: Provide the user with the author, title of the program, and its function.
void programInformation()
{
    cout << "*********************************************" << endl;
    cout << "***           Author: -                   ***" << endl; 
    cout << "***         Statistical Calculator           ***" << endl;
    cout << "*********************************************" << endl;
}

//Module: inputArrayValues
//Description: Ask the user to input values between 3 and 30 elements for the array to hold. Also validates that the user inputs a total of values between 3 and 30.
void inputArrayValues (double array[], int SIZE, int &count)
{
    double number = 0;
    // Basic information about what the user can input. Does not repeat.
    cout << "Please enter values one at a time." <<endl;
    cout << "Up to a maximum of 30 values and a minimum of 3 values." << endl;
    cout << "Only positive values are accepted or the program will not work." << endl;
    cout << "With the exception, please enter the value -1.0 to stop entering values." << endl;

    // Do-While Loop
    // Variable count is counting how many values the user inputs for later calculation
    while (number != 1.0)
    {
        for (int i = 0; i < SIZE; i++)
        {
            cout << "Please enter a value or enter -1.0 to stop entering values" << endl;
            cin >> number;
            array[i] = number;
            if (number != 1.0)
            {
                count++;
            }

        }
    }

    if (count < 3 || count > SIZE)
    {
        cout << "Invalid total number of values." << endl;
        cout << "The total number of values must between 3 and 30 values." <<endl;
        cout << "This program will now close..." << endl;
        cout << "Thank you for using this program." << endl;
    }
}
//Module: printListOriginal
//Description: Prints out the values that the user entered 5 values per line
void printListOriginal (double array[], int count)
{
    int i = 0;
    while (i < count)
    {
        cout <<array[i] << " ";
        i++;
        if (i > 5)
        {
            cout << endl;
            i= 0;
        }
    }
}
//Module: sortAscending
//Description: Sorts the given inputs in Ascending Order and Displays the sorted list.
void sortAscending (double array[], int count)
{
    int i;
    int j = 0;
    double temp;
    for (i = 0; i < count; i++)
    {
        if (array[j+1] < array[j])
        {
            temp = array[j];
            array[j] = array[j+1];
            array [j+1] = temp;
        }
    }
    int k = 0;
    while (k < count)
    {
        cout <<array[k] << " ";
        k++;
        if (k > 5)
        {
            cout << endl;
            k= 0;
        }
    }
}
//Function: comupteAverage
//Description: Computes the average of the given inputs.
double computeAverage (double array[], int count)
{
    double sum = 0.0;
    double resultA;
    for (int i =0; i < count; i++)
    {
        sum = sum + array[i];
    }
    resultA = sum / count;
    return resultA;
}
//Function: computeMedian
//Description: Computes the Median of the given inputs.
double computeMedian (double array[], int count)
{
    double resultM;
    if ((count % 2) == 0)
    {
        resultM = (array[count/2] + (array[count/2] -1.0) /2.0);
    }
    else
        resultM = array[count/2];
    return resultM;
}
//Function: computeSTD
//Description: Computes the Standard Deviation of the given inputs.
double computeSTD (double array[], int count, double average)
{
    double temp;
    double sum = 0;
    double resultV;
    for(int i = 0; i < count; i++)
    {
        temp = pow((array[i] - average), 2);
        sum = sum + temp;
    }
    //Account for Sample Standard Deviation N-1
    resultV = sqrt(sum/(count -1));
    return resultV;
}
//Module: printCalculations
//Description: Prints the Average, Median, and Standard Deviation
void printCalculations (double average, double median, double std)
{
    cout << "The average is: " << average << endl;
    cout << "The median is: " << median << endl;
    cout << "The Standard Deviation is: " << std << endl;
}

最佳答案

这是因为你的函数声明是这样的:-

double computeSTD (double array[], int count);

你用三个参数定义了它:-

double computeSTD (double array[], int count, double average)

关于c++ - LNK2019 - 未解析的外部符号 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26837013/

相关文章:

c++ - 设置小部件初始大小

c++ - 使用 fstream 写入类型 vector

c++ - C/C++ 服务器,通过 stdin/stdout 与客户端通信(阻塞在 stdin 上直到读取了一些字节)

c++ - 需要一个库来获取Win CE下的性能计数器数据,c++代码

c++ - 仅覆盖自定义数据结构的迭代器的 operator*()

c++ - gettimeofday() 的单位是什么?

c++ - 来自 dll 的函数调用 [表观调用括号前的表达式必须具有(指向)函数类型]

c++ - opencv中的Vec4i是什么

c++ - 将 move 语义与 std::pair 或 std::tuple 一起使用

c++ - 以下递归程序的最后一行是如何工作的?