← Back to Streams
Question 635
Percent Formatter
Percent Formatter
Write a functionvoid printPercent(ostream& out, double ratio)that takes a ratio between 0 and 1, multiplies it by 100, and writes the result tooutwith exactly one decimal place, immediately followed by a%sign and a newline. Usefixedandsetprecision(1). Examples:printPercent(cout, 0.75)prints75.0%,printPercent(cout, 1.0)prints100.0%,printPercent(cout, 0.333)prints33.3%,printPercent(cout, 0)prints0.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
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.