Skip to content

Instantly share code, notes, and snippets.

@garbuchev
Created March 23, 2014 15:40
Show Gist options
  • Save garbuchev/9724846 to your computer and use it in GitHub Desktop.
Save garbuchev/9724846 to your computer and use it in GitHub Desktop.
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