Starting from:

$29.99

CS150 Lab 12 Solution

Have the user input a filename to read in ints from. Print each to the screen, one per line and keep a running total.
Print the total at the end. If the file does not exist say so and do not print the total.
Test Case 1:
File contents (ask user to enter filename, the file they enter contains this): 2 4 6 8 10
Sample output:
Read 2 from file. Read 4 from file.
Read 6 from file.
Read 8 from file.
Read 10 from file.
Total is 30.
Test Case 2:
File contents (ask user to enter filename, the file they enter contains this):
1
3
5
7
Sample Output:
Read 1 from file.
Read 3 from file.
Read 5 from file.
Read 7 from file.
Total is 16.
Test Case 3:
(nonexistent file – user enters nonexistent filename)
Sample output:
Failed to open file.

More products