Beispiel #1
0
        static void Main(string[] args)
        {
            int side1, side2, side3;
            int input;



            Console.WriteLine("1. Enter Tringle Dimension");
            Console.WriteLine("2. Exit");

            // int input = int.Parse(Console.ReadLine());

            do
            {
                Console.WriteLine("Choose the Menu from above");
            } while (!int.TryParse(Console.ReadLine(), out input) || input > 2 || input < 1);


            if (input == 1)
            {
                Console.Write("Input side 1 of triangle: ");
                side1 = Convert.ToInt32(Console.ReadLine());

                /* string side1 = Console.ReadLine();
                 * int number;
                 * if (!Int32.TryParse(side1, out number))
                 * {
                 *  Console.WriteLine("Please Select Side 1 value again ");
                 *  Console.ReadLine();
                 * }
                 *
                 *
                 *
                 * while(side1 < 1)
                 * {
                 *   Console.WriteLine("Incorect Input ");
                 *   Console.Write("Input side 1 of triangle: ");
                 *   string side1;
                 *   side1 = Convert.ToInt32(Console.ReadLine());
                 *
                 * } */

                Console.Write("Input side 2 of triangle: ");
                side2 = Convert.ToInt32(Console.ReadLine());

                Console.Write("Input side 3 of triangle: ");
                side3 = Convert.ToInt32(Console.ReadLine());

                /*if (side1 == side2 && side1 == side2)
                 * {
                 *  Console.Write("This is an equilateral triangle.\n");
                 * }
                 * else if (side1 == side2 || side1 == side2 || side1 == side2)
                 * {
                 *  Console.Write("This is an isosceles triangle.\n");
                 * }
                 * else
                 * {
                 *  Console.Write("This is a scalene triangle.\n");
                 * } */

                string typeOfTriangle = TriangleSolver.Analyze(side1, side2, side3);
                Console.WriteLine("\n\n The Triangle is {0} Type", typeOfTriangle);
                Console.ReadLine();
            }

            else
            {
                System.Environment.Exit(1);
            }

            // else
            // {
            //    Console.WriteLine("Incorrect Input");
            // }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Boolean check;
            int     dimension1 = 0;
            int     dimension2 = 0;
            int     dimension3 = 0;
            String  result;

            do
            {
                check = true;
                try
                {
                    Console.WriteLine("Menu:");
                    Console.WriteLine("1. Enter triangle dimension");
                    Console.WriteLine("2. Exit");
                    int choice = int.Parse(Console.ReadLine());

                    if (choice == 1)
                    {
                        dimension1 = CheckDimension();

                        dimension2 = CheckDimension();

                        dimension3 = CheckDimension();
                    }

                    else if (choice == 2)
                    {
                        Environment.Exit(0);
                    }

                    else
                    {
                        Console.WriteLine("Please select the valid option");
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Enter the valid input");
                }
            } while (check == true);

            result = TriangleSolver.Analyze(dimension1, dimension2, dimension3);
            Console.WriteLine(result);
            Console.ReadLine();

            int CheckDimension()
            {
                int dimension = 0;

                do
                {
                    check = true;
                    try
                    {
                        Console.WriteLine("Enter the dimension");
                        dimension = int.Parse(Console.ReadLine());
                        if (dimension <= 0)
                        {
                            Console.WriteLine("Enter the dimension greater than zero");
                            check = true;
                        }
                        else
                        {
                            Console.WriteLine("Dimension entered successfully");
                            check = false;
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Enter the valid dimension");
                        check = true;
                    }
                } while (check == true);
                return(dimension);
            }
        }