Question: Write a program to read and total all numbers in a file Prompt the user for a file name Using exception handling: Output a message,

Write a program to read and total all numbers in a file
Prompt the user for a file name
Using exception handling:
Output a message, Could not open file - exiting, if the file could not be opened/read and exit the program
Output a message, Invalid number: , plus the bad line if the value on the line is not a floating point number
Print the grand total at the end of the program
nums1.txt contains:
3
4.5
apple
1
banana
num2.txt contains:
1.2
3.6
4.2
-2.1
bad
4
Sample Run #1(bold, underlined text is what the user types):
File? nums1.txt
Invalid number: apple
Invalid number: banana
Grand total: 8.5
Note: This is an introductore level class and this problem is meant to completed through a mixture of inputs/outputs, and exceptions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!