← Back to Streams
Question 607
Write a Formatted Price
Write a Formatted Price
Write a functionvoid writePrice(const string& filename, double p)that opensfilenamewith anofstream(the starter does this asout) and writes one line:Price:followed by a space andpshown with exactly two digits after the decimal point, then a newline. ForwritePrice("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 isPrice: 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
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.