Trouble with structs

Hello all,

i have an assignment that requires 2 structs (1 of them nested inside the other) with an array of the struct. the user will input data such as name and test grades and the program is to average them and give a letter grade based on the average.

i thought i had it all right when i went to start debugging and got the following errors:

Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "void __cdecl PrintStudent(struct Student,int)" (?PrintStudent@@YAXUStudent@@H@Z) referenced in function _main student C:\Users\Student\Desktop\school\C++\lab 1\student\student\student.obj 1

Error LNK1120 2 unresolved externals student C:\Users\Student\Desktop\school\C++\lab 1\student\Debug\student.exe 1

Error LNK2019 unresolved external symbol "struct Student __cdecl GetData(struct Student,int)" (?GetData@@YA?AUStudent@@U1@H@Z) referenced in function _main student C:\Users\Student\Desktop\school\C++\lab 1\student\student\student.obj 1

i have no idea what these mean as i am just starting an intermediate c++ course and cant figure out what the technical definition means.

below is the code i am using.

** Edited 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
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
 //this program is used to enter student data and average the test scores giving an overall grade
#include <iomanip>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

//This struct will define the name for the student
struct FullName
{
	string fName;
	char mInitial;
	string lName;
};

//This struct will define the students name using the previous struct and use an array for grades, a float for the average grade, and a char for the letter grade
struct Student
{
	FullName name;
	float tests[3];
	float average;
	char grade;
};

//this function is used to determine the average of the array of 3 floats in the student struct
float DetermineAverage(float[3]);

//this function is used to determine the letter grade the student will receive by comparing the average to the grading scale
char DetermineGrade(float);

//this function will populate the two structs with user inputed data
Student GetData(Student [], int);

//this function will print the data on the screen, showing full name, the 3 tests, the average, and the final letter grade
void PrintStudent(Student [], int);

int main()
{
	//declaring roster as an array of the Student Struct
	const int NUM_STUDENTS = 2;
	Student roster[NUM_STUDENTS];

	GetData(roster, NUM_STUDENTS);

	PrintStudent (roster, NUM_STUDENTS);

	return 0;

}

//this function is used to determine the average of the array of 3 floats in the student struct
float DetermineAverage(float t[3])
{
	cout << "DetermineAverage Function has been called" << endl;
	//determine the average of the tests
	return (t[0] + t[1] + t[2]) / 3;

}

//this function is used to determine the letter grade the student will receive by comparing the average to the grading scale
char DetermineGrade(float a)
{
	char letterGrade;

	cout << "DetermineGrade Function has been called!" << endl;

	if (a >= 90)
		letterGrade = 'A';
	if (a < 90 && a >= 80)
		letterGrade = 'B';
	if (a < 80 && a >= 70)
		letterGrade = 'C';
	if (a < 70 && a >= 60)
		letterGrade = 'D';
	else
		letterGrade = 'F';

	return letterGrade;
}

//this function will populate the two structs with user inputed data
Student GetData(Student roster[], int s)
{
	int r;
	char grade;
	char letter;
	string name;
	float average;

	for (r = 0; r < s; r++)
	{
		//enter the students name
		cout << "What is the students first name? ";
		cin >> name;
		roster[r].name.fName = name;
		cin.ignore();
		cout << "What is the students middle initial? ";
		cin >> letter;
		roster[r].name.mInitial = letter;
		cin.ignore();
		cout << "What is the students last name? ";
		cin >> name;
		roster[r].name.lName = name;
		cin.ignore();
		//enter the students tests
		cout << "Enter the students test scores: ";
		cin >> roster[r].tests[0];
		cin >> roster[r].tests[1];
		cin >> roster[r].tests[2];
		cin.ignore();

		//call the DetermineAverage function to average the three tests
		average = DetermineAverage(roster[r].tests);
		roster[r].average = average;

		//call to the DetermineGrade function to determine letter grade
		grade = DetermineGrade(average);
		roster[r].grade = grade;
	}

	return;
}

//this function will print the data on the screen, showing full name, the 3 tests, the average, and the final letter grade
void PrintStudent(Student roster[], int s)
{
	int r;
	cout << "PrintStudent function has been called: ";

	for (r = 0; r < s; r++)
	{
		cout << "Student Name: " << roster[r].name.fName << roster[r].name.mInitial << "." << roster[r].name.lName << endl;
		cout << "Test 1: " << roster[r].tests[1] << endl;
		cout << "Test 2: " << roster[r].tests[2] << endl;
		cout << "Test 3: " << roster[r].tests[3] << endl;
		cout << "Average: " << roster[r].average << endl;
		cout << "Final Grade: " << roster[r].grade << endl;
	}
}


looking for help as to where i went wrong and why so i dont make this mistake again.

Thanks!
Last edited on
Those are linker errors. The first is telling that you're trying to call a function PrintStudent(struct Student,int), but that you haven't defined any such function. Note that this:

void PrintStudent(Student, int);

does not match this:

void PrintStudent(Student roster[], int s)
Last edited on
thank you mikeyboy, that clarified it for me and i figured it out.

but now that i can run it it allows me to enter the name of the student but then doesnt stop to allow me to enter the test scores, it just keeps going around the loop until it crashes.

ok fixed that issue, but now it is saying that GetData needs to return a value. I tried making it a void function but got errors, and its not accepting a return of the roster array.

it accepts the values for name, test scores, and calls the function to average them and assign a letter grade and lets me do that for the loop, but when finish inputting the last part of the array it doesnt continue to the PrintStudent function, it just crashes.

i would try and make pointers for it all but we havent gone over that in class and i would probably get points off for that.

Thanks for any help you can give!
Last edited on
GetData needs to return a value

So... um... make it return a value.
Topic archived. No new replies allowed.