Example #1
0
        static void Main(string[] args)
        {
            //Menu
            bool correctInputMenu = false;

            while (true)
            {
                try
                {
                    do
                    {
                        Console.WriteLine("Menu");
                        Console.WriteLine("*****");
                        Console.WriteLine("Please select from below Menu");
                        Console.WriteLine("1: Enter triangle dimension");
                        Console.WriteLine("2: Exit");

                        int menuInput = Convert.ToInt32(Console.ReadLine());

                        if (menuInput == 1)
                        {
                            //input for triangle from user
                            bool correctInput = false;
                            while (true)
                            {
                                try
                                {
                                    do
                                    {
                                        Console.WriteLine("Enter the sides of the triangle:");
                                        Console.WriteLine("********************************");

                                        Console.WriteLine("Enter the first side of triangle:");
                                        int a = Convert.ToInt32(Console.ReadLine());
                                        Console.WriteLine("Enter the second side of triangle:");
                                        int b = Convert.ToInt32(Console.ReadLine());
                                        Console.WriteLine("Enter the third side of triangle:");
                                        int c = Convert.ToInt32(Console.ReadLine());

                                        String value = TriangleSolver.Analyze(a, b, c);

                                        Console.WriteLine(value);
                                        correctInput = true;
                                    }while (correctInput == false);
                                    break;
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("Invalid input, please enter the number as input");
                                    continue;
                                }
                            }
                        }
                        else if (menuInput == 2)
                        {
                            Environment.Exit(0);
                        }
                        else
                        {
                            Console.WriteLine("Please choose the option from menu");
                        }
                    }while (correctInputMenu == false);
                    break;
                }
                catch (Exception e)
                {
                    Console.WriteLine("Invalid input, Please select the correct menu option from available list of Menu");
                    continue;
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            int sideA      = 0;
            int sideB      = 0;
            int sideC      = 0;
            int menuOption = 0;

            do
            {
                do
                {
                    Console.WriteLine("Please make a menu choice:");
                    Console.WriteLine("1.Enter Triangle DImensions");
                    Console.WriteLine("2.Exit");

                    try
                    {
                        menuOption = int.Parse(Console.ReadLine());
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Please enter either 1 or 2");
                        Console.ReadKey();
                        Console.Clear();
                    }
                } while (menuOption == 0 || menuOption < 0 || menuOption > 2);

                switch (menuOption)
                {
                case 1:
                    Console.Clear();
                    Console.WriteLine("Please enter side A:");
                    try
                    {
                        sideA = int.Parse(Console.ReadLine());
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Please enter a number");
                        Console.ReadKey();
                        Console.Clear();
                        break;
                    }

                    Console.WriteLine("Please enter side B:");
                    try
                    {
                        sideB = int.Parse(Console.ReadLine());
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Please enter a number");
                        Console.ReadKey();
                        Console.Clear();
                        break;
                    }

                    Console.WriteLine("Please enter side C:");
                    try
                    {
                        sideC = int.Parse(Console.ReadLine());
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Please enter a number");
                        Console.ReadKey();
                        Console.Clear();
                        break;
                    }

                    TriangleSolver.Analyze(sideA, sideB, sideC);
                    Console.ReadKey();
                    Console.Clear();
                    break;

                case 2:
                    Environment.Exit(0);
                    break;

                default:
                    break;
                }
            } while (menuOption == 1);
        }