Andrew Costa
Andrew Costa

Reputation: 1

C++ Standard Deviation assignment need help correcting error

Trying to write a program that uses an array to calculate standard deviation. It keeps giving me an error:

"LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) ConsoleApplication7777 C:\Users\Gregory\Desktop\ConsoleApplication7777\ConsoleApplication7777\MSVCRTD.lib(exe_main.obj) 1"

Here is my code:

#include "stdafx.h"
#include<iostream>
#include<cmath>

using namespace std;

double standard_Deviation(double x[], int n);

//Main Function here
void Main()
{
    //declare variables here
    double x[100];
    double sDeviation;
    int i;
    int n;

//input number values here
cout << "Enter n value";
cin >> n;

//input array values here
cout << "Enter values:" << endl;

for (i = 0; i < n; i++)
    cin >> x[i];
//call standard deviation function
sDeviation = standard_Deviation(x, n);

//outputting standard deviation
cout << "Standard Deviation:" << sDeviation << endl;
//give it time to think
system("pause");

}

double standard_Deviation(double x[], int n)
{
double sd = 0;
double mean=0;
for (int i = 0; i<n; i++)
    mean = mean + x[i];
mean = mean / n;
for (int i = 0; i<n; i++)
    sd = sd + pow((x[i] - mean), 2);
sd = sd / n;
sd = sqrt(sd);
return sd;
return mean;
} //end of standard deviation

Upvotes: 0

Views: 133

Answers (2)

mathematician1975
mathematician1975

Reputation: 21351

Replace

void Main()

with

int main()

Applications require a main function (that has int return type) and that is what the linker is complaining about as you have not provided one due to your typo with an upper case M.

Upvotes: 0

decltype_auto
decltype_auto

Reputation: 1736

Attend case-sensitivity of C and C++; the main routine the linker looks for is

int main() {/**/}

not

void Main(){/* ... */}

Upvotes: 1

Related Questions