← Back to Streams
Question 637
Receipt to Any Stream
Receipt to Any Stream
Write a functionvoid receipt(ostream& out, const vector<pair<string, double>>& items)that writes one line per item — the item name, a single space, and the price with exactly 2 decimal places — and then a final lineTotal:followed by the sum of all prices, also with 2 decimals. Every line ends with a newline. Usefixedandsetprecision(2). Write everything toout. With no items only the lineTotal: 0.00is printed. Do NOT write a main function.
Expected Output:
tea 2.50 cake 7.00 Total: 9.50 water 1.00 Total: 1.00 Total: 0.00
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Streamsostream
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.