static void Main() { try { int number = int.Parse(Console.ReadLine()); if (number < 0) { throw new ArgumentOutOfRangeException("Number should be positive or 0."); } SquareRoot.CalculateSquareRoot(number); } catch (FormatException) { Console.Error.WriteLine("Invalid number"); } catch (ArgumentOutOfRangeException) { Console.Error.WriteLine("Invalid number"); } catch (OverflowException) { Console.Error.WriteLine("Invalid number"); } finally { Console.WriteLine("Good bye"); } }
static void Main(string[] args) { // ax^2 + bx + c = 0 double x1, x2; int Square; Square = SquareRoot.Square(1, -2, -3, out x1, out x2); Console.WriteLine("x1 = {0}\tx2 = {1}\tSquare = {2}", x1, x2, Square); }
static void Main(string[] args) { //Create new list of 10,000 random numbers. List <double> randList = new List <double>(); randList = MakeNumList(); //Create new SquareRoot and test types, setting error for Heron method. SquareRoot Hroot = new SquareRoot(0.0001); RootTest testRoot = new RootTest(); //Loop through list of random numbers and print out heron vs test for each number. foreach (double i in randList) { Console.WriteLine(Hroot.CalcRoot(i) + ", " + testRoot.CalcRoot(i)); } Console.ReadLine(); }