CJCoding With Joseph
15free / daySign inCreate account

Percent Formatter

Write a function void printPercent(ostream& out, double ratio) that takes a ratio between 0 and 1, multiplies it by 100, and writes the result to out with exactly one decimal place, immediately followed by a % sign and a newline. Use fixed and setprecision(1).

Examples: printPercent(cout, 0.75) prints 75.0%, printPercent(cout, 1.0) prints 100.0%, printPercent(cout, 0.333) prints 33.3%, printPercent(cout, 0) prints 0.0%.

Do NOT write a main function.

Expected Output:

75.0%
100.0%
33.3%
0.0%

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

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