7. A Sum of Numbers

Providing Data on Standard Input

The data on standard input can be provided all at once or in several portions. For example, we can provide the data for the previous program all at once. Start the program and when asked to type in 5 numbers, type all five of them on the same line separated by spaces. Then hit Enter. You might get an output like this:

Type in five numbers:
7 11 -3 0 22
The current sum is: 7
The current sum is: 18
The current sum is: 15
The current sum is: 15
The current sum is: 37

Or, you can provide the input data in two portions:

Type in five numbers:
11  0.3
The current sum is: 11
The current sum is: 11.3
10  11.56  2
The current sum is: 21.3
The current sum is: 32.86
The current sum is: 34.86

A user is also allowed to provide more data then the program requires. The additional data will be ignored.

If a user does not provide enough data, the program will wait until the user types in more data.