← Back to Streams
Question 615
Receipt with Total
Receipt with Total
Write a functionvoid writeReceipt(const string& filename, const vector<double>& prices)that opensfilenamewith anofstreamand writes one line per price, numbered from 1, in the formItem 1: 3.50. After all the items write a final lineTotal:followed by a space and the sum of all the prices. Every price and the total are written with exactly two digits after the decimal point (fixed,setprecision(2)). Each line ends with a newline. For prices {3.5, 6.75} the file must contain exactly: Item 1: 3.50 Item 2: 6.75 Total: 10.25 Do NOT write a main function.
Expected Output:
Item 1: 3.50 Item 2: 6.75 Total: 10.25 Item 1: 1.00 Item 2: 2.50 Item 3: 0.25 Total: 3.75
= newline. The output ends with a newline — print one after the last line.
Hints4 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.