Quick Question

I need to write a void definition that updates one value with another and then have the new value displayed in the calling environment.

The last part is the somewhat confusing portion. That is, I assume with a certain degree of certainty that the calling environment is where the function is called from inside the int main (). Correct?

To do this I have so far:

1
2
3
4
void update(int sum, int Score)
{
sum = sum + score
}


Which I believe is incorrect. :) I should have an & with the int sum..as in int& sum?

Or am I far off the mark here? It's one of those things where I think I understand it, or I'm so far off the mark. :)
I should have an & with the int sum..as in int& sum?
yes: http://www.cplusplus.com/doc/tutorial/functions2/
void update(int sum, int Score) takes two integers (sum and Score) then adds them together places that into sum. Unfortunately that doesn't do much as that is local data and does not effect main().

If you need to keep the function returning void, then what you could do is exactly what you said. Add the ampersand taking the address of sum instead of the int sum.
Thanks, I just wanted to make sure I was understanding it correctly.
Topic archived. No new replies allowed.