CJCoding With Joseph
15free / daySign inCreate account

Average with Missing-File Branch

Write a function void printAverage(const string& filename). If the file cannot be opened, print exactly Could 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 print Average:  followed by their mean shown with exactly one digit after the decimal point (see Expected Output).

One test passes the path missing_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
Topics:
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.