Skip to content

Instantly share code, notes, and snippets.

@cbcwebdev
Created March 22, 2012 03:56
Show Gist options
  • Save cbcwebdev/2155703 to your computer and use it in GitHub Desktop.
Save cbcwebdev/2155703 to your computer and use it in GitHub Desktop.
public class Calculator
{
public static int Add(IEnumerable<int> operands)
{
return operands.Sum();
}
}
public class CalculatorApp
{
public void Start(string prompt)
{
do {
try {
Console.WriteLine(prompt);
var operands = GetInput();
Console.WriteLine(Calculator.Add(operands));
}
catch(Exception ex) { Console.WriteLine(ex); }
} while(true);
}
private IEnumerable<int> GetInput()
{
var input = Console.ReadLine();
return input.Split(' ').Cast<int>();
}
}
public static void Main()
{
var calculator = new CalculatorApp();
calculator.Start("Type in some numbers for me to add!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment