The reason is the order of evaluation of parameters within an expression. The language does not specify the order in which sub-expressions within an expression are evaluated. In this case, you have two sub-expressions that causes the problem:
- The value of the function call to score.
- The value of total.
You need to call the function and grab its return value before printing it to ensure that the function is actually called before printing the value of total.
int total = 0; int myscore = score(sol, total); cout << myscore << "/" << total;