﻿/*
 * Problem 1. Square root
 * Write a program that reads an integer number and calculates and prints its square root.
 * If the number is invalid or negative, print Invalid number.
 * In all cases finally print Good bye.
 * Use try-catch-finally block.
 */

using System;

class P01_SquareRoot
{
    static void Main()
    {
        // input
        Console.Write("positive number: ");
        string input = Console.ReadLine();

        // program logic
        try
        {
            double number = double.Parse(input);

            if (number < 0)
            {
                throw new System.ArgumentOutOfRangeException("Invalid number");
            }

            Console.WriteLine(Math.Sqrt(number));
        }
        catch (System.FormatException fe)
        {
            Console.WriteLine("Invalid number" + fe);
        }
        catch (System.ArgumentOutOfRangeException ae)
        {
            Console.WriteLine("Please type a number > 0" + ae);
        }
        finally
        {
            Console.WriteLine("Good bye.");
        }
    }
}