Calling by Reference and value

Write your question here.

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
#include <iostream>
using namespace std;

bool figureGrade(int score, char &);

int main()
{
	int score;
	char grade;
	cout << "Please enter a score" << endl;
	cin >> score;
	cout << "The score you entered is " << score << endl;
	bool figureGrade(int score, char &);
	if (figureGrade(score, grade))
	{
		cout << "The student's grade is" << grade << endl;
	}
	return 0;
}

bool figureGrade(int score, char &)
{
	char character;
	if (score > 0 && score <= 100)
	{
		if (score > 90 && score <= 100)
			character = 'A';
		return true;
		if (score > 80 && score <= 89)
			character = 'B';
			return true;
			if (score > 70 && score <= 79)
				character = 'C';
				return true;
				if (score > 60 && score <= 69)
					character = 'D';
		return true;
		if (score <= 59)
			character = 'F';
		return true;
	}
	else
	{
		cout << "Invalid score. No grade given" << endl;
		return false;
	}
}





I was wanting to see if I could get a little help with this program. I feel like I am really close to having this program complete, but for some reason I can't seem to call the letter grade back from the function at the bottom. If I put a invalid score in, it will return my cout at the bottom of the function, but when I try to return the letter grades, all it gives me is an odd symbol. Any help would be appreciated. Thank you.
Line 13
You've already declared your function prototype at Line 4, so no need to declare it again.

Line 21
It would be helpful to give your char& parameter a name, like so:
bool figureGrade(int score, char& grade)
Then instead of using the variable character, you can just use the parameter grade.

Also have a read on the tutorial on functions.
http://www.cplusplus.com/doc/tutorial/functions/
Thank you very much. I see now why it wasn't working before. I need to cover functions again, thats probably my worst thing right now. Thank you!
Topic archived. No new replies allowed.