error lnk2019 and lnk1120

I am working on an assignment in my intro to C++ class and I keep running into the same problem. Every time I try to run the program, I get the following message:

"main.obj : error LNK2019: unresolved external symbol "void __cdecl arrayDisplay(int *,int,int *)" (?arrayDisplay@@YAXPAHH0@Z) referenced in function _main
1>C:\Users\Adam\Desktop\C++ Assignments\AdamSpaay_Assign8\Debug\AdamSpaay_Assign8.exe : fatal error LNK1120: 1 unresolved externals"

If anyone can offer me any help, I'd be greatly appreciative. I'm still relatively new to C++, and I don't know a lot of the advanced techniques yet, but as far as I can tell, what I have below SHOULD work, aside from the error I keep getting, and I don't understand at all what's wrong.

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Write a function that accepts as arguements the following: A) an array of intergers
// and B) an interger that indicates the number of elements in the array.
// Modify the program to allow the used to input up to 10 intergers and the used input in an array.
// Validation is not required.
// If the used inputs -1 exit the input loop.
// Find the median value after the user has input their interger values.
// Display all intergers input by the user and the median value.
// Demonstrate "pointer prowess"

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

//function prototypes:
void arrayDisplay(int*, int, int*);
void clearBoard(int*, int&, int);
void medianDisplay(int*, int);
int main()
{
	//Local variables
	const int ARRAYSIZE = 10;
	int *input;
	int *pointer;
	int userInput = 0;
	int incrCounter = 0;
	int displayCounter = 0;

	input = new int[ARRAYSIZE];


	//Set pointer equal to array
	pointer = input;
	pointer+=incrCounter;

	do
	{
		if (incrCounter < ARRAYSIZE)
		{
			cout << "Enter a number into the array, or enter -1 to quit." <<incrCounter + 1 << "of" << ARRAYSIZE;
			cin >> userInput;
			if (userInput != -1)
			{
				*pointer = userInput;
				incrCounter++;
				pointer++;
			}
		}
		else
		{
			cin.ignore();
			cout << "The array cannot hold more than 10 values.";
			cin.get();
		}
			

	} while (userInput != '-2');

		//Displaying the inputs
		input = pointer;
		arrayDisplay(input, incrCounter, pointer);
		cin.ignore();
		cin.get();

		//Displaying the median
		medianDisplay(input, incrCounter);

		

		//Clearing the array
		clearBoard(input, incrCounter, ARRAYSIZE);
		cin.ignore();
		cout << "The array has been cleared.";
		cin.get();

		

		return 0;
}

void arrayDislpay(int input[], int incrCounter, int *pointer)
{
	int displayCounter = 0;

	pointer = input;
	cout << "The number of elements currently in the array is: "<< incrCounter;
	for (displayCounter = 0; displayCounter < incrCounter; displayCounter++)
	{
		cout << pointer << "  ";
		pointer++;
	}

	return;
}

void medianDisplay (int input[], int incrCounter)
{
	double middleInt;
	double arrayAvg;
	double determinateDecimal;
	int medianInt;

	middleInt = incrCounter / 2;
	determinateDecimal = middleInt- static_cast <int> (middleInt);
	medianInt = static_cast<int>(middleInt);

	if (determinateDecimal > 0)
	{
		cout << "The median is " << input[medianInt] << endl;
				
	}
		else 
		{
			arrayAvg = (input[medianInt] + input[medianInt + 1]) / 2.0;
			cout << "The median is " << arrayAvg << endl;
		}

	return;
}

void clearBoard(int input[], int &incrCounter, int ARRAYSIZE)
{
	delete [] input;
	input = 0;
	incrCounter = 0;
	input = new int[ARRAYSIZE];

	return;
}
You have a typo on line 81: arrayDislpay

Last edited on
Thanks, coder777. The code finally starts up, but now no matter what I enter for my array values, the program keeps telling me to enter new values instead of moving me to the next part of the program. And when I put it all ten values, it just tells me "the array cannot hold more than ten values" over and over.
Nevermind. I figured out what was wrong. However, now I'm getting a bunch of garbage results when the program tells me what the numbers in the array are, and of course, the median result is garbage, as well.

Anyone have any idea of what I'm doing wrong?
This is what I've got now. I keep getting garbage results for my median and the display of the numbers in my array.

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*Adam Spaay
CIS 330 C++ Programming
Median Function
4/5/2012*/
// Write a function that accepts as arguements the following: A) an array of intergers
// and B) an interger that indicates the number of elements in the array.
// Modify the program to allow the used to input up to 10 intergers and the used input in an array.
// Validation is not required.
// If the used inputs -1 exit the input loop.
// Find the median value after the user has input their interger values.
// Display all intergers input by the user and the median value.
// Demonstrate "pointer prowess"

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

//function prototypes:
void arrayDisplay(int*, int, int*);
void clearBoard(int*, int&, int);
void medianDisplay(int*, int);
int main()
{
	//Local variables
	const int ARRAYSIZE = 10;
	int *input;
	int *pointer;
	int userInput = 0;
	int incrCounter = 0;
	int displayCounter = 0;

	input = new int[ARRAYSIZE];


	//Set pointer equal to array
	pointer = input;
	pointer+=incrCounter;

	do
	{
		if (incrCounter < ARRAYSIZE)
		{
			cout << "Enter a number into the array, or enter -1 to quit." <<incrCounter + 1 << "of" << ARRAYSIZE;
			cin >> userInput;
			if (incrCounter < 10)
			{
				*pointer = userInput;
				incrCounter++;
				pointer++;
			}
			else
			{
			cin.ignore();
			cout << "The array cannot hold more than 10 values.";
			cin.get();
			}
		}
			

		} while (userInput != -1);

		//Displaying the inputs
		input = pointer;
		arrayDisplay(input, incrCounter, pointer);
		cin.ignore();
		cin.get();

		//Displaying the median
		medianDisplay(input, incrCounter);

		

		//Clearing the array
		clearBoard(input, incrCounter, ARRAYSIZE);
		cin.ignore();
		cout << "The array has been cleared.";
		cin.get();

		

		return 0;
}

void arrayDisplay(int input[], int incrCounter, int *pointer)
{
	int displayCounter = 0;

	pointer = input;
	cout << "The number of elements currently in the array is: "<< incrCounter;
	for (displayCounter = 0; displayCounter < incrCounter; displayCounter++)
	{
		cout << pointer << "  ";
		pointer++;
	}

	return;
}

void medianDisplay (int input[], int incrCounter)
{
	double middleInt;
	double arrayAvg;
	double determinateDecimal;
	int medianInt;

	middleInt = incrCounter / 2;
	determinateDecimal = middleInt- static_cast <int> (middleInt);
	medianInt = static_cast<int>(middleInt);

	if (determinateDecimal > 0)
	{
		cout << "The median is " << input[medianInt] << endl;
				
	}
		else 
		{
			arrayAvg = (input[medianInt] + input[medianInt + 1]) / 2.0;
			cout << "The median is " << arrayAvg << endl;
		}

	return;
}

void clearBoard(int input[], int &incrCounter, int ARRAYSIZE)
{
	delete [] input;
	input = 0;
	incrCounter = 0;
	input = new int[ARRAYSIZE];

	return;
}
heres your problem:

1
2
3
4
void arrayDisplay (int*, int, int*);
void arrayDisplay (int[], int, int*)
{
}


the declaration and definition are different, either change the declaration to int[], int, int* or change the definition parameter to int*, int, int*
When you execute the line 64:
input = pointer;

pointer is pointing to a place in memory that is after the input you just got.

You can just remove that line. input already points where you need it to.


@GFreak45:

int[] and int* are equivalent when used as types for parameters to functions. That isn't the problem.
Thanks, Cire. That got my median to come out correctly.

I'm still having problems getting the array to display as the numbers entered into it, and not as the data addresses. The all come out as 000E4C7C and things like that.

Also, the program keeps counting -1 as one of the numbers entered into the array, and I want that to be the value that ends the entry of numbers into the array. I'm trying to work them out myself, and not having much luck.
I'm still having problems getting the array to display as the numbers entered into it, and not as the data addresses. The all come out as 000E4C7C and things like that.


That's because you're printing the value contained by a pointer as opposed to the value pointed at.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
void arrayDisplay(int input[], int incrCounter, int *pointer)
{
	int displayCounter = 0;

	pointer = input;
	cout << "The number of elements currently in the array is: "<< incrCounter;
	for (displayCounter = 0; displayCounter < incrCounter; displayCounter++)
	{
		cout << *pointer << "  ";
		pointer++;
	}

	return;
}


Notice that the pointer is dereferenced in line 9.

You could just as easily have written it:

1
2
3
4
5
6
void arrayDisplay(int input[], int incrCounter, int *pointer)
{
	cout << "The number of elements currently in the array is: "<< incrCounter;
	for (int displayCounter = 0; displayCounter < incrCounter; displayCounter++)
		cout << input[displayCounter] << ' ' ;
}


I'm not sure why you're passing pointer, as it doesn't supply any information to the function at all.
Thanks again, Cire. Like I said, I'm still learning all of this, and arrays and pointers have been tough for me to get my head around.

My only problems now are to get the program to stop counting -1 as part of the array and figure out how to get the program to continue running after all 10 values are entered.
Topic archived. No new replies allowed.