Whats wrong with my code?

Hey. I'm getting some erros i can't understand

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace System;
using namespace std;

double CalcMean(double, int);


int main(array<System::String ^> ^args)
{
    int choosenNum;
	int *arrayNum;
	double values;
	double nValues;

	cout << "How many values would you like to calculate?";
	cin >> choosenNum;
	arrayNum = new int[choosenNum];

	for(int n=0; n<choosenNum; n++)
	{
		cout << "Enter number: ";
		cin >> arrayNum[n];
	}

	double meanValue = CalcMean(values, nValues);

	cout << "Mean value: " << meanValue << endl;


	Console::ReadKey();

	
}
double CalcMean(double values[], double nValues)
{
	double sum = 0;
    for (int i = 0; i < nValues; ++i)
        sum += values[i];
    return sum / (double(nValues));

}


Errors:
error LNK1120: 2 unresolved externals
error LNK2019: unresolved external symbol
error LNK2028: unresolved token (0A000344)


The first problem is that the prototype on line 9 doesn't match the implementation on line 38.

The second problem is that you don't do anything with the entered numbers (arrayNum).

The third problem is that your leave nValues uninitialize. You use choosenNum to enter the numbers, but not for the calculation later on.

on line 43: if nValues is 0 your program crashes (why do you cast nValues to double? It is already double)
It would be helpful if you could show us the whole of those linker errors - especially the part that would tell us which symbols were unresolved!

I'm guessing one of them is array, which I don't see defined anywhere in your code.

What is System::String? What header file is it defined in? Any particular reason why you're not using the STL string class?

What is the purpose of the ^ symbols in the definition of main? That's not a C++ construct I'm familiar with - is it some kind of platform-specific extension?
Last edited on
What is System::String?
It's the .NET string

What is the purpose of the ^ symbols in the definition of main?
It's the CLI extension 'garbage collector pointer'
It's the .NET string
It's the CLI extension 'garbage collector pointer'
Ah, OK. .NET and CLI is an area I've managed to avoid so far. Thanks for the info!
Topic archived. No new replies allowed.