Struct help with error! Short!

Hey guys I am getting a LNK2019 error aka unresolved external symbol

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
  #include <stdio.h>
#include <string>
#include <cstdlib>
#include <iostream>


using namespace std;

enum departmentSchool {
	History, ComputerScience, LiberalArts, Math, Biology
};
enum daysOfTheWeek {
	M, T, W, R, F
};


struct Courses {
	string courseID;
	departmentSchool department;
	daysOfTheWeek day;
	int time;
	int credits;
	int enrollment;

};

void find_courses(Courses all[], Courses result[], Courses a);


Courses get_course_info();


void print_course_info(Courses all[]);


void get_max_enrollment(Courses all[]);

void get_least_credits(Courses all[]);




int main() {

	string exit;
	Courses all[10];
	Courses result[3];
	Courses a;

	do {
		for (int i = 0; i < 10; i++) {
			Courses temp = get_course_info();
			all[i] = temp;
		}

		get_max_enrollment(all);

		get_least_credits(all);


		std::cout << "Please enter the Department of the course. (0 = History 1 = ComputerScience 2 = LiberalArts 3 = Math 4 = Biology" << endl;

		int control = 0;

		while (control < 1) {
			int dep;
			std::cin >> dep;

			if (a.department == History || ComputerScience || LiberalArts || Math || Biology) {
				a.department = (departmentSchool)dep;
				control += 1;

			}
			else {
				std::cout << " Please re-enter the course department correctly \n";

			}

		}

		std::cout << "Please enter the Course Day of the week." << endl;

		control = 0;

		while (control < 1) {
			int day;
			std::cin >> day;

			if (a.department == M || T || W || R || F) {
				a.day = (daysOfTheWeek)day;
				control += 1;

			}
			else {
				std::cout << " Please re-enter the course day correctly (remember to use capital letter) \n";

			}

		}

		std::cout << "Please enter the Course Start Time" << endl;

		control = 0;

		while (control < 1) {
			std::cin >> a.time;

			if (a.time == 8 || 9 || 12 || 3 || 6) {
				control += 1;

			}
			else {
				std::cout << " Please re-enter the course time correctly \n";

			}

		}

		void find_courses(Courses& all, Courses& result, Courses a);


	} while (exit != "q" || "Q");


	return 0;
}

void find_courses(Courses all[], Courses result[], Courses a) {
	int sizeResult = 0;
	for (int i = 0; i < 10; i++) {
		if (all[i].department == a.department && all[i].day == a.day && all[i].time == a.time) {
			if (sizeof(result) < 3) {
				result[sizeResult] = all[i];
				sizeResult++;
			}
			else {
				std::cout << "There are more than 3 matches, Please look over Student Course Selection Guide";
			}

		}

	}

	if (sizeResult == 0) {
		std::cout << "No matches occured, Please try again" << endl;
	}

	if (sizeResult > 0 && sizeResult < 4) {
		for (int i = 0; i < sizeResult; i++) {
			print_course_info(result);
		}
	}

};


Courses get_course_info() {

	Courses temp;

	std::cout << "Please enter a Course ID (use 5 digits than last the semester character*Capitalized* " << endl;

	int control = 0;

	while (control < 1) {
		std::cin >> temp.courseID;

		if (temp.courseID[6] == 'F' || 'S' || 'U') {
			control += 1;

		}
		else {
			std::cout << " Please re-enter the course ID correctly (Remember to use Capital letter for semester) \n";

		}

	}

	std::cout << "Please enter the Department of the course." << endl;

	control = 0;

	while (control < 1) {
		int dep;
		std::cin >> dep;

		if (temp.department == History || ComputerScience || LiberalArts || Math || Biology) {
			temp.department = (departmentSchool)dep;
			control += 1;

		}
		else {
			std::cout << " Please re-enter the course department correctly \n";

		}

	}

	std::cout << "Please enter the Course Day of the week." << endl;

	control = 0;

	while (control < 1) {
		int day;
		std::cin >> day;

		if (temp.day == M || T || W || R || F) {
			temp.day = (daysOfTheWeek)day;
			control += 1;

		}
		else {
			std::cout << " Please re-enter the course day correctly (remember to use capital letter) \n";

		}

	}

	std::cout << "Please enter the Course Start Time" << endl;

	control = 0;

	while (control < 1) {
		std::cin >> temp.time;

		if (temp.time == 8 || 9 || 12 || 3 || 6) {
			control += 1;

		}
		else {
			std::cout << " Please re-enter the course time correctly \n";

		}

	}

	std::cout << "Enter the amount of credits \n";
	std::cin >> temp.credits;

	std::cout << "Enter the Enrollment limit";
	std::cin >> temp.enrollment;


	return temp;

}

void print_course_info(Courses all)
{
	std::cout << "Course ID: " << all.courseID << endl;
	std::cout << "Course Department: " << all.department << endl;
	std::cout << "Course Days of the week: " << all.day << endl;
	std::cout << "Course Time Start: " << all.time << endl;
	std::cout << "Course Credits: " << all.credits << endl;
	std::cout << "Course Enrollment Limit: " << all.enrollment << endl;
}


void get_max_enrollment(Courses all[]) {
	Courses temp;
	temp.enrollment = 0;
	for (int i = 0; i < sizeof(all); i++) {
		if (all[i].enrollment > temp.enrollment) {
			temp = all[i];
		}
	}

	std::cout << "The class with the largest enrollment is " << temp.courseID << endl;
}

void get_least_credits(Courses all[]) {
	Courses temp;
	temp.credits = 0;
	for (int i = 0; i < sizeof(all); i++) {
		if (all[i].credits < temp.credits) {
			temp = all[i];
		}
	}

	std::cout << "The class with the least amount of credits is " << temp.courseID << endl;
}


This is the entire code but the portion causing the error is

1
2
3

void print_course_info(Courses all[]);


If anyone could explain to me what is wrong and how to fix it I'd appreciate it.
Last edited on
Courses result[3]; // This is an array

print_course_info(result); // Here you call the function giving it the array as an argument

void print_course_info(Courses all) // Here you are, not taking in array "result" as an array.

std::cout << "Course ID: " << all.courseID << endl; // Nor do you use it as an array


In other words: The prototype of print_course_info(...) does not match the implementation due to the missing [].

A loop like this does not work (line 262/274):

for (int i = 0; i < sizeof(all); i++) {

all is implicitly converted to a pointer, hence the sizeof will return the size of the pointer. You need to pass the number of elements besides the array.

Something like this doesn't work either:

if (temp.time == 8 || 9 || 12 || 3 || 6) {

It needs to be:

if (temp.time == 8 || temp.time == 9 || etc.) {
Topic archived. No new replies allowed.