Percent Formatter
mediumQuestion 635Write 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, so print one after the last line.
Hints2 available
Sign in to use hintsTopics
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.