Esempio n. 1
0
        static void Main(string[] args)
        {
            bool value = true;

            do
            {
                Console.WriteLine("Select any option: ");
                Console.WriteLine("1.Enter Triangle Dimensions");
                Console.WriteLine("2.Exit");

                string userOption = Console.ReadLine();

                if (userOption == "1")
                {
                    value = true;
                    do
                    {
                        Console.WriteLine("\nEnter 3 sides of triangle:");
                        try
                        {
                            int side1 = Convert.ToInt32(Console.ReadLine());
                            int side2 = Convert.ToInt32(Console.ReadLine());
                            int side3 = Convert.ToInt32(Console.ReadLine());

                            if (side1 <= 0 || side2 <= 0 || side3 <= 0)
                            {
                                Console.WriteLine("The side of triangle cannot be less than or equal to zero.");
                            }
                            value = false;

                            Console.WriteLine(TriangleSolver.Analyze(side1, side2, side3));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("ERROR: Please Try Again " + e.Message);
                        }
                    } while (value);
                    value = true;
                }
                else if (userOption == "2")
                {
                    value = false;
                }
                else
                {
                    Console.WriteLine("Wrong Input,Choose Option Again\n");
                }
            } while (value);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Boolean value = false;


            value = true;
            do
            {
                Console.WriteLine("\n1.Enter Triangle Dimensions");
                Console.WriteLine("2.Exit");

                string menu = "";
                Console.WriteLine("\nChoose the menu");
                menu = Console.ReadLine();

                if (menu == "1")
                {
                    Console.WriteLine("Enter First Integer");
                    int firstInput = int.Parse(Console.ReadLine());

                    string userinput = Console.ReadLine(); int a;
                    bool   input1IsInteger = int.TryParse(userinput, out a);
                    if (input1IsInteger == false)
                    {
                        Console.WriteLine("Please Enter the Integer");
                        Console.ReadLine();

                        Console.WriteLine("Enter Second Integer");


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


                        string userinput2 = Console.ReadLine(); int b;
                        bool   input2IsInteger = int.TryParse(userinput, out b);
                        if (input2IsInteger == false)
                        {
                            Console.WriteLine("Please Enter the Integer");
                            Console.ReadLine();
                        }


                        Console.WriteLine("Enter Third Integer");
                        int thirdInput = int.Parse(Console.ReadLine());


                        string userinput3 = Console.ReadLine(); int c;
                        bool   input3IsInteger = int.TryParse(userinput, out c);

                        if (input3IsInteger == false)
                        {
                            Console.WriteLine("Please Enter the Integer");
                            Console.ReadLine();
                        }


                        Console.WriteLine(TriangleSolver.Analyze(firstInput, SecondInput, thirdInput));
                        Console.ReadLine();
                    }
                }
                else if (menu == "2")
                {
                    value = false;
                }
                else
                {
                    Console.WriteLine("\nPlease Enter Valid Menu Option");
                }
            }while (value);
        }