← Back to Streams
Question 587
Average with Missing-File Branch
Average with Missing-File Branch
Write a functionvoid printAverage(const string& filename). If the file cannot be opened, print exactlyCould not open file(followed by a newline) and return. Otherwise the file contains one or more integers separated by spaces or newlines, for example: 90 75 82 83 Read all of them and printAverage:followed by their mean shown with exactly one digit after the decimal point (see Expected Output). One test passes the pathmissing_dir/scores.txt, whose folder does not exist. Do NOT write a main function.
Expected Output:
Average: 82.5 Could not open file
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Streamsifstream
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.