Write a program to input text from a file and output the total of all the “numbers” in the file. A
number will be any sequence of digits followed by a “non-digit” (a period or a comma are nondigits too). For instance, “3.14159” in the file would be counted as two numbers to add to the
total: a 3 and 14159; “21,756.54” would add three numbers to the total: 21, 756 and 54.
Numbers will not be split over 2 lines.
Here is the precise dialog required:
Program to count the total
of the numbers in a file.
You will be asked to enter
the name of a file.
Written by Name.
Enter the name of a file to count: mywords.txt
The original file
has been counted and the sum of
all numbers is 1380

New Download