CJCoding With Joseph
15free / daySign inCreate account

Write a Formatted Price

Write a function void writePrice(const string& filename, double p) that opens filename with an ofstream (the starter does this as out) and writes one line: Price: followed by a space and p shown with exactly two digits after the decimal point, then a newline.

For writePrice("price_a.txt", 12.5) the file must contain the single line:
Price: 12.50

The test reopens the file and prints every line, so that is also the output. (For 3.0 the line is Price: 3.00.)

Do NOT write a main function.

Expected Output:

Price: 12.50
Price: 3.00

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

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