Created
March 23, 2014 15:40
-
-
Save garbuchev/9724846 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class SumOf5Numbers | |
{ | |
static void Main() | |
{ | |
Console.WriteLine("Please enter 5 numbers separated by space:"); | |
string input = Console.ReadLine(); | |
string[] numbersText = input.Split(); | |
double[] numbers = new double[5]; | |
bool check = true; | |
for (int i = 0; i < 5; i++) | |
{ | |
bool checkArray = double.TryParse(numbersText[i], out numbers[i]); | |
check = (check && checkArray); | |
} | |
double sum = 0; | |
if (check == true) | |
{ | |
for (int i = 0; i < 5; i++) | |
{ | |
sum += numbers[i]; | |
} | |
Console.WriteLine("sum={0}",sum); | |
} | |
else | |
{ | |
Console.WriteLine("invalid entry"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment