SHOW:
|
|
- or go back to the newest paste.
| 1 | namespace Chap4Exc7 | |
| 2 | {
| |
| 3 | class Program | |
| 4 | {
| |
| 5 | static void Main() | |
| 6 | {
| |
| 7 | int[] numbers = new int[5]; | |
| 8 | ||
| 9 | Console.WriteLine("Please enter 5 numbers");
| |
| 10 | for ( int i = 0; i <= numbers.Length - 1 ; i++) | |
| 11 | {
| |
| 12 | string bString = Console.ReadLine(); | |
| 13 | - | string bString = Console.ReadLine(); |
| 13 | + | |
| 14 | //adds the readed value to the epmty variaables of the array | |
| 15 | bool tryParse = int.TryParse(bString, out numbers[i]); | |
| 16 | Console.WriteLine(tryParse ? "Enter the next number" : "Invalid number"); | |
| 17 | } | |
| 18 | ||
| 19 | int sum = (numbers[0] + numbers[1] + numbers[2] + numbers[3] + numbers[4]); | |
| 20 | Console.WriteLine("The sum of your number is : " + sum);
| |
| 21 | } | |
| 22 | } | |
| 23 | } |