LNK2019 Problem with functions

I've looked through many threads here with the similar problem but I cannot seem to fix my code.
The exact errors are as follow


1>WillBeeler_Prog1.obj : error LNK2019: unresolved external symbol "void __cdecl DisplayPercentages(double * const,char * const)" (?DisplayPercentages@@YAXQANQAD@Z) referenced in function _main
1>WillBeeler_Prog1.obj : error LNK2019: unresolved external symbol "void __cdecl DisplayCounts(int * const,char * const)" (?DisplayCounts@@YAXQAHQAD@Z) referenced in function _main
1>WillBeeler_Prog1.obj : error LNK2019: unresolved external symbol "void __cdecl InitializeCharList(char * const)" (?InitializeCharList@@YAXQAD@Z) referenced in function _main
1>C:\Users\Will\Desktop\Programs\CSI140\CSCI140\Assignment8\WillBeeler_Prog1\Debug\WillBeeler_Prog1.exe : fatal error LNK1120: 3 unresolved externals


Here is the code so far...
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#include <iostream>
#include <fstream>
#include <cctype>
#include <iomanip>
#include <string>

using namespace std;



int counts[26];
char charList[26];
double percent[26];
string fileName;

void GetCounts(int counts[]);
bool AnalyzeAnotherFile();
void InitializeCounts(int counts[]);
void FindPercentages(int counts[], double percent[]);
void DisplayPercentages(double percent[], char charList[]);
void SortPercentages(double percent[], char charList[]);
void DisplayCounts(int counts[], char charList[]);
void InitializeCharList(char charList[]);

int main()
{  
  do
  {
    InitializeCounts(counts);
	GetCounts(counts);
    InitializeCharList(charList);
    DisplayCounts(counts, charList);
    FindPercentages(counts, percent);
    SortPercentages(percent,charList);
    DisplayPercentages(percent,charList);
  } while (AnalyzeAnotherFile());
  return 0;
} // end main


void InitializeCounts(int counts[])
{
	for( int i = 0; i < 26 ; i++)
	{
		counts[i] = 0;
	}
}



void SortPercentages(double percent[], char charList[])
{
	int max;
	double hold;
	char holdchar;
	int size = 26;
	for( int i = 0; i < size - 1; i++)
	{
		//find the position of the smallest element
		max = i;
		for(int k = i + 1; k < size; k++)
		{
			if (percent[k] > percent [max])
			{
				max = k;
			}
		}
		//swap
		hold = percent[max];
		percent[max]= percent[i];
		percent[i]=hold;

		holdchar = charList[max];
		charList[max] = charList[i];
		charList[i] = holdchar;

	}

}

void GetCounts(int counts[])
{
	cout << "Enter the name of the input file: ";
	cin >> fileName;
	
	
	ifstream inFile;
	inFile.open(fileName.c_str());

	do
	{
	char i;
	
	inFile >> i;

	if ( i = 'a')
	{
		counts[0]++;
	}
	else if ( i = 'b')
	{
		counts[1]++;
	}
	else if ( i = 'c')
	{
		counts[2]++;
	}
	else if ( i = 'd')
	{
		counts[3]++;
	}
	else if ( i = 'e')
	{
		counts[4]++;
	}
	else if ( i = 'f')
	{
		counts[5]++;
	}
	else if ( i = 'g')
	{
		counts[6]++;
	}
	else if ( i = 'h')
	{
		counts[7]++;
	}
	else if ( i = 'i')
	{
		counts[8]++;
	}
	else if ( i = 'j')
	{
		counts[9]++;
	}
	else if ( i = 'k')
	{
		counts[10]++;
	}
	else if ( i = 'l')
	{
		counts[11]++;
	}
	else if ( i = 'm')
	{
		counts[12]++;
	}
	else if ( i = 'n')
	{
		counts[13]++;
	}
	else if ( i = 'o')
	{
		counts[14]++;
	}
	else if ( i = 'p')
	{
		counts[15]++;
	}
	else if ( i = 'q')
	{
		counts[16]++;
	}
	else if ( i = 'r')
	{
		counts[17]++;
	}
	else if ( i = 's')
	{
		counts[18]++;
	}
	else if ( i = 't')
	{
		counts[19]++;
	}
	else if ( i = 'u')
	{
		counts[20]++;
	}
	else if ( i = 'v')
	{
		counts[21]++;
	}
	else if ( i = 'w')
	{
		counts[22]++;
	}
	else if ( i = 'x')
	{
		counts[23]++;
	}
	else if ( i = 'y')
	{
		counts[24]++;
	}
	else if ( i = 'z')
	{
		counts[25]++;
	}//end if
	
	}while (!inFile.eof());

}

void FindPercentages(int counts[], double percent[])
{
	int total = 0;

	for (int i = 0; i < 26; i++)
	{
		total = total + counts[i];
	}
	
	for (int i = 0; i < 26; i++)
	{
		percent[i] = (counts[i] / total) * 100;   
	}
}

bool AnalyzeAnotherFile()
{
	char repeat = 'y' ;
	cout << "Would you like to analyze another file (y/n)?";
	cin >>  repeat;
	repeat = tolower(repeat);

	if( repeat == 'y')
	{
		return true;
	}
	else
	{
		return false;
	}

}


void InitializeCharList(char charList[])
{
	charList[0] = 'a';
	charList[1] = 'b';
	charList[2] = 'c';
	charList[3] = 'd';
	charList[4] = 'e';
	charList[5] = 'f';
	charList[6] = 'g';
	charList[7] = 'h';
	charList[8] = 'i';
	charList[9] = 'j';
	charList[10] = 'k';
	charList[11] = 'l';
	charList[12] = 'm';
	charList[13] = 'n';
	charList[14] = 'o';
	charList[15] = 'p';
	charList[16] = 'q';
	charList[17] = 'r';
	charList[18] = 's';
	charList[19] = 't';
	charList[20] = 'u';
	charList[21] = 'v';
	charList[22] = 'w';
	charList[23] = 'x';
	charList[24] = 'y';
	charList[25] = 'z';
}

void DisplayCounts(int counts[], char charList[])
{
	cout << "Letter Counts\n";
	
	for( int i=0; i < 26; i++)
	{
		if( i%6 == 0)
		{
			cout << endl;
		}

		cout << setw(4) << charList[i] << setw(5) << counts[i];
	}

	int total = 0;

	for (int i = 0; i < 26; i++)
	{
		total = total + counts[i];
	}

	cout << endl;
	cout << "Number of letters: " << total << endl << endl;

}

void DisplayPercentages(double percent[], char charList[])
{

	cout << "Sorted percentages\n";
	
	for( int i=0; i < 26; i++)
	{
		if( i%6 == 0)
		{
			cout << endl;
		}

		cout << setw(4) << charList[i] << setw(5) << setprecision(2) << percent[i];
	}
}



Thank you.
Last edited on
Try rebuilding it it should work. One note you have assignments not equality tests on lines 275 and 302.
Last edited on
Wow, like a charm. Thank you!
Last edited on
Your welcome.
Haha so it turns out that is totally fixed and it runs like a champ only it is completely wrong. When I input a text file it reads all the characters into the letter a. So a will have 26000 or however many hits and every other letter will have zero. The file is text from Dracula and I can read it. They are not all a...
Topic archived. No new replies allowed.