Could you give input/output for an example run?
Code:
cout << "Your total grade is " << setprecision(3)
<< grade(midterm, final, sum/count) << endl
<< "Also final grade (outside function) is: " << final
<< setprecision(prec) << endl;
Within this statement, the value of final is used twice and it is changed in the meantime (grade has side-effects). I'm not sure if this is undefined like i = i++; but to be safe you might break it up into two statements:
Code:
cout << "Your total grade is " << setprecision(3)
<< grade(midterm, final, sum/count) << endl;
cout << "Also final grade (outside function) is: " << final
<< setprecision(prec) << endl;
Anyway, for me it gives the expected output (fin == final) either way.