Receipt with Total
mediumQuestion 615Write a function void writeReceipt(const string& filename, const vector<double>& prices) that opens filename with an ofstream and writes one line per price, numbered from 1, in the form Item 1: 3.50. After all the items write a final line Total: 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, so 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.