我是C ++的新手,也不知道确切的位置。我的程序似乎出现错误,标记为LNK2019-未解析的外部符号。

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

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

以下提供的是我的源代码的副本。

#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/

10-11 15:58