CJCoding With Joseph
15free / daySign inCreate account

Return the Larger of Two Values

Write a function template larger(T first, T second) that returns the larger of the two values as a T. Use an if statement, not std::max. When the two values are equal, return first.

The tests print one result per line for larger(3, 9), larger(-2, -7), larger(2.5, 1.75), larger(4, 4) and larger(std::string("pear"), std::string("apple")) (strings compare alphabetically).

Do NOT write a main function.

Expected Output:

9
-2
2.5
4
pear

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
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.