Undefined reference to 'getLetterGrade(char)'

I'm trying to write a program that averages a students quiz, midterm, and final scores, gives them a letter grade, determines if the number of classes they have attended is over 30, and tells them if they failed or passed the class. Under 30 classes attended will fail a student, and an average under 60 will fail a student.

On line 32, it gives me the error: Undefined reference to 'getLetterGrade(char)'

Any ideas? Thanks in advance.

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
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

float averageQuizzes(int, int, int , int );
float averageFinal(int, int, float);
char getLetterGrade(char);
void ifPassedClass(int, int );


int main(int argc, char *argv[]) {
	string firstname,lastname;
	char grade;
	int quiz1,quiz2,quiz3,quiz4,midterm,final,attendance;
	double quiz_average,final_average;
	fstream myfile;
	myfile.open("C:/Users/------/Downloads/bettergrades.txt");
	while(!myfile.eof()) {
	
	
	myfile >> firstname >> lastname >> quiz1 >> quiz2 >> quiz3 >> quiz4 >> midterm >> final >> attendance;
	
	
	
	
	
	quiz_average = averageQuizzes(quiz1,quiz2,quiz3,quiz4);
	final_average = averageFinal(midterm,final,quiz_average);
	grade = getLetterGrade(final_average);
	cout << lastname << ", " << firstname << "\t" << setprecision(0) << fixed << final_average << "\t" << grade << "\t";
	ifPassedClass(final_average,attendance);
	cout << endl;
}

myfile.close();
	return 0;
}

// this function gets four assignment grades and averages them
float averageQuizzes(int quiz1, int quiz2, int quiz3, int quiz4) {

return (quiz1+quiz2+quiz3+quiz4)/4;

}

// this function gets a midterm, a final and the assignment average and averages them 
float averageFinal(int final, int midterm, float quiz_average) {

return (quiz_average+midterm+final)/3.0;

}
    
    
//  this functions takes the final average and returns the correspondingletter grade
char getLetterGrade(int final_average) {

char grade;

if (final_average >= 90) grade = 'A';
else if ((final_average < 90) && (final_average >= 80)) grade = 'B';
else if ((final_average < 80) && (final_average >= 60)) grade = 'C';
else if ((final_average < 60) && (final_average >= 50)) grade = 'D';
else grade = 'F';

}
//  this function takes the final average and the number of classes attended to determine if the student passes
void ifPassedClass(int final_average, int attendance) {
	if ((final_average < 60 || (attendance < 30))) cout << "Failed";
	else cout << "Passed";
}
At line 10, the prototype states that the parameter needs to be of type char
 
char getLetterGrade(char);


Next at line 32, you attempt to call the function with a parameter final_average of type double.
 
grade = getLetterGrade(final_average);


And last, the function definition at line 58 states that the parameter should be an integer
 
char getLetterGrade(int final_average)


That's three different types for the parameter.

The compiler itself is complaining only that lines 10 and 58 disagree. Decide which is correct and use the same type at both line 10 and line 58 and the compiler should be ok. By the way, that function must have a return statement - it should return a result of type char - but that's a separate problem.
Topic archived. No new replies allowed.