← Functions & Pass-by-Value vs. Pass-by-Reference

Running Total

hard

main is already complete: it reads a count n, then n more integers one at a time, calling add_to(&total, amount) for each. Your job is just add_to – it’s called repeatedly against the same total variable in main, and each call needs to add to whatever’s already there, not reset it.

This is the same out-parameter pattern as the first exercise, but used across multiple calls instead of one – total in main persists across the whole loop, while each call to add_to only sees it for an instant through the pointer. If your first test passes but later ones look like only the last amount “stuck,” that’s a sign you’re overwriting *total instead of adding to it.

Your solution

"Run" uses the sample stdin ("3\n1 2 3"). "Submit" checks your code against all 4 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution