CJCoding With Joseph
15free / daySign inCreate account

Restore Stream State

Write a function void printMoney(ostream& out, double v) that writes a dollar sign followed by v with exactly two decimals and a newline ($1234.50 for 1234.5), then leaves out in exactly the state it found it.

The tests print 3.14159 through the same stream afterwards (see Expected Output).

Do NOT write a main function.

Expected Output:

$1234.50
3.14159
2.5
$1.00
100

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

Hints4 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.