locked
Why do I get these errors? RRS feed

  • Question

  • Hi. I'm getting some erros i can't understand. Also, when I try to run the program it says that it can't find the .exe in the debug folder.


    Code:

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

    • Moved by Damon Zheng Wednesday, December 19, 2012 11:21 AM forum retired (From:Visual C++ Language)
    Monday, December 3, 2012 9:45 AM

Answers

  • Hi. I'm getting some erros i can't understand. Also, when I try to run the program it says that it can't find the .exe in the debug folder.
    The signature of your implementation of CalcMean() does not match that of the declaration and usage.
     
    double CalcMean(double, int); // declaration
     
    double CalcMean(double values[], double nValues) // implementation
     
    Actually, I think neither is correct. You want
     
    double CalcMean(double values[], int nValues)
     
    There are also some logical errors in your code.
     

    David Wilkinson | Visual C++ MVP
    • Proposed as answer by Elegentin Xie Tuesday, December 11, 2012 9:09 AM
    • Marked as answer by Elegentin Xie Wednesday, December 12, 2012 8:33 AM
    Monday, December 3, 2012 10:51 AM