I'm stumped on why the line:
cout << "Your average in this course is " << average() << " and your letter grade is " << convert_to_letterGrade() << "\n";
does not work, whereas the following works (one cout is split into 2):
cout << "Your average in this course is " << average();
cout << << " and your letter grade is " << convert_to_letterGrade() << "\n";
This code is in a void function that is a public member of the class Grades
. average()
calculates and stores the result in the private member variable averageScore
, and also returns averageScore
. convert_to_letterGrade()
returns a char
value based on the value of averageScore
and an error message if the average score is not reasonable, and both functions are private members of the class.
In the first case, I get the error message from convert_to_letterGrade()
first, THEN followed by what the cout
statement was supposed to print. The cout
statement prints the correct averageScore
value, but when I stepped into convert_to_letterGrade()
, the function was still using a garbage value for averageScore
, whereas the second one works perfectly fine and convert_to_letterGrade()
is also using the correct averageScore
value.
Why is this?