Gregc. said:
Keith Thompson wrote: [...]
Let's look at your function again:
| char getGrade(double mark) {
|
|
| if (mark>= 85)
| return ('A');
| else if (mark >= 75)
| return ('B');
| else if (mark >= 65)
| return ('C');
| else if (mark >= 50)
| return ('D');
|
|
| return (mark);
| }
The last return statement is doing something that's legal (because the
value of mark, which is of type double, will be implicitly converted
to type char), but that doesn't make any sense.
The easiest thing for me to do would be to give you the answer. I
know exactly how to fix your getGrade function so it will do what (I
presume) you want it to do. Instead, I'm trying to help you solve the
problem yourself.
Think about this: Under what circumstances will the "return (mark);"
statement be executed? In those circumstances, what is the right
thing to do? What value do you want to return from your function?
I appreciate you not giving me the answer. What I want to return is a
char ie A, B etc, only if the student has met the criteria. Someting
like return getGrade (char).
And what do you want to return if the student *hasn't* met the
criteria?
The function always has to return something, and what it returns
always has to be of type char.
More specifically, what char value should getGrade return when
mark < 50?