Summing Three Numbers from Any File

Create several more files in Notepad containing three integers separated by some whitespace. Save them in your home directory as "3nums1.txt", "3nums2.txt", "3nums3.txt", etc.

Then write a program that asks the user which file to open. Then it should open that file, and read the three integers from the file. It should then display (on the screen) the total of the integers.

Which file would you like to read numbers from: 3nums2.txt
Reading numbers from file "3nums2.txt"

6 + 3 + 3 = 12

 

Which file would you like to read numbers from: 3nums4.txt
Reading numbers from file "3nums4.txt"

7 + 2 + 5 = 14


©2013 Graham Mitchell

This assignment is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.
Creative Commons License