← Back to Templates
Question 748
Increase a Value Through a Reference
Increase a Value Through a Reference
Write a function template increaseBy(T& value, U amount) with two type parameters. It adds amount to value and returns nothing. Because value is a reference, the caller's variable itself grows.
The two types are independent: a double can be increased by an int, and an int by another int. The tests increase a double balance of 10.5 by 4, an int score of 40 by 2, and a double of 1.25 by 0.5, printing each variable after its call, one per line.
Do NOT write a main function.
Expected Output:
14.5 42 1.75
= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Templates
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.