Beispiel #1
0
        static void Main(string[] args)
        {
            bool check = true;

            do
            {
                Console.WriteLine("1.Enter Triangle Dimensions");

                Console.WriteLine("2.Exit");

                int a = int.Parse(Console.ReadLine());

                check = true;
                switch (a)
                {
                case 1:

                    Console.WriteLine("\n\nEnter All sides of Triangle\n");
                    int x = 0; int y = 0; int z = 0;

                    try
                    {
                        Console.Write("Enter Value of Side 1 for Triangle: ");
                        x = Convert.ToInt32(Console.ReadLine());

                        Console.Write("Enter Value of Side 2 for Triangle: ");
                        y = Convert.ToInt32(Console.ReadLine());

                        Console.Write("Enter Value of Side 3 for Triangle: ");
                        z = Convert.ToInt32(Console.ReadLine());
                    }catch (Exception e)
                    {
                        Console.WriteLine("\n\nEnter valid input");
                        continue;
                    }


                    if ((((x + y) > z) && ((y + z) > x) && ((x + z) > y)) == false)
                    {
                        Console.WriteLine("\nThe given sides doesn't form the triangle");
                        continue;
                    }

                    if ((x <= 0) || (y <= 0) || (z <= 0))
                    {
                        Console.WriteLine("Not a valid side input");
                        continue;
                    }

                    Console.WriteLine(TriangleSolver.Analyse(x, y, z));

                    break;

                case 2:
                    Console.WriteLine("Exiting...");
                    check = false;
                    System.Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Wrong input! Enter 1 or 2 only \n ");
                    break;
                }
            } while (check);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            int  userInput;
            bool checkStatus = true;
            int  side1;
            int  side2;
            int  side3;

            do
            {
                bool sideCheck = true;
                Console.WriteLine("\n\n##Select from the mentioned menu\n");
                Console.WriteLine("1. Enter triangle dimensions");
                Console.WriteLine("2. Exit");

                try
                {
                    userInput = Convert.ToInt32(Console.ReadLine());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Enter the input in Int Format.");
                    continue;
                }
                switch (userInput)
                {
                case 1:

                    do
                    {
                        try
                        {
                            Console.WriteLine("Enter side 1");
                            side1 = Convert.ToInt32(Console.ReadLine());

                            Console.WriteLine("Enter side 2");
                            side2 = Convert.ToInt32(Console.ReadLine());

                            Console.WriteLine("Enter side 3");
                            side3 = Convert.ToInt32(Console.ReadLine());

                            if (((side1 + side2) > side3) && ((side2 + side3) > side1) && ((side1 + side3) > side2))
                            {
                                Console.WriteLine("\nIt forms a triangle\n");
                                Console.WriteLine("Triangle is : " + TriangleSolver.Analyze(side1, side2, side3));
                            }
                            else
                            {
                                Console.WriteLine("It doesn't form a triangle");
                            }

                            checkStatus = true;
                            sideCheck   = true;
                            break;
                        }

                        catch (Exception e)
                        {
                            Console.WriteLine("\nEnter the side in Int format");
                            sideCheck = false;
                        }
                    }while (!sideCheck);
                    break;

                case 2:
                    Console.WriteLine("\n\n##Exiting##");
                    checkStatus = false;
                    break;

                default:
                    Console.WriteLine("Select the valid option 1 or 2 only.");
                    break;
                }
            } while (checkStatus);
        }