Write a Formatted Price
easyQuestion 607Write 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, so print one after the last line.
Hints2 available
Sign in to use hintsTopics
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.