Пример #1
0
        static void Main(string[] args)
        {
            TriangleSolver triangleInst   = new TriangleSolver();
            var            input          = "";
            bool           shouldContinue = true;

            while (shouldContinue)
            {
                Console.WriteLine(
                    "Please enter one of the following:" + "\n"
                    + "1. Enter Triangle dimensions." + "\n"
                    + "2. Exit");

                Console.Write("Enter a option - ");
                input = Console.ReadLine();
                int num = -1;
                if (!int.TryParse(input, out num))
                {
                    Console.WriteLine("Not an integer. Please enter valid input.");
                }
                else
                {
                    int option = Convert.ToInt32(input);
                    switch (option)
                    {
                    case 1:
                        int a, b, c;
                        Console.Write("Enter a value for side 1: ");
                        while (!int.TryParse(Console.ReadLine(), out a))
                        {
                            Console.Write("The value must be of integer type, please enter again: ");
                        }
                        Console.Write("Enter a value for side 2: ");
                        while (!int.TryParse(Console.ReadLine(), out b))
                        {
                            Console.Write("The value must be of integer type, please enter again: ");
                        }
                        Console.Write("Enter a value for side 3: ");
                        while (!int.TryParse(Console.ReadLine(), out c))
                        {
                            Console.Write("The value must be of integer type, please enter again: ");
                        }
                        Console.WriteLine(triangleInst.Analyze(a, b, c));
                        break;

                    case 2:
                        shouldContinue = false;
                        break;
                    }
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            bool   validInput = false;
            string inputString;

            while (validInput == false)
            {
                do
                {
                    Console.WriteLine("Please choose the number from given below.");
                    Console.WriteLine("1. Enter the triangle Dimensions.");
                    Console.WriteLine("2. Exit");
                    inputString = Console.ReadLine();
                    Console.WriteLine();;

                    if (inputString != "1" && inputString != "2")
                    {
                        Console.WriteLine("That is not a valid selection");
                    }
                    else if (int.Parse(inputString) == 1)
                    {
                        validInput = true;
                        int Edge1;
                        int Edge2;
                        int Edge3;

                        Edge1 = ValidInput("Edge1");

                        Edge2 = ValidInput("Edge2");

                        Edge3 = ValidInput("Edge3");

                        Console.WriteLine(TriangleSolver.Analyze(Edge1, Edge2, Edge3));
                        Console.WriteLine();
                    }
                    else if (int.Parse(inputString) == 2)
                    {
                        validInput = true;
                    }
                } while (inputString != "2");
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            bool menuValidate = false, inputValid = false;
            int  side1, side2, side3;

            Console.WriteLine("Assignment 2 Solution");
            Console.WriteLine("-----------------------------------------\n");
            do
            {
                Console.WriteLine(" 1. Enter triangle dimensions: \n 2. Exit \n");
                Console.Write("Please select any option from menu: ");
                string menu = Console.ReadLine();
                int    menuInteger;
                bool   success = Int32.TryParse(menu, out menuInteger);

                if (success == true)
                {
                    if (menuInteger == 1 || menuInteger == 2)
                    {
                        menuValidate = true;
                        if (menuInteger == 1)
                        {
                            do
                            {
                                Console.Write("\n Enter triangle First Side: ");
                                string firstSide = Console.ReadLine();

                                Console.Write("\n Enter triangle Second Side: ");
                                string secondSide = Console.ReadLine();

                                Console.Write("\n Enter triangle Third Side: ");
                                string thirdSide = Console.ReadLine();

                                bool success1 = Int32.TryParse(firstSide, out side1);
                                bool success2 = Int32.TryParse(secondSide, out side2);
                                bool success3 = Int32.TryParse(thirdSide, out side3);

                                if (success1 == true && success2 == true && success3 == true)
                                {
                                    inputValid = true;
                                    string triangleOutput = TriangleSolver.Analyze(side1, side2, side3);
                                    Console.WriteLine(triangleOutput);
                                    Console.ReadLine();
                                }
                                else
                                {
                                    Console.WriteLine("\nYou did a mistake!! please enter a integer value");
                                }
                            } while (inputValid == false);
                        }
                        else if (menuInteger == 2)
                        {
                            Environment.Exit(0);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("\nYou did a mistake!! please enter a integer value for menu");
                }
            } while (menuValidate == false);
        }
Пример #4
0
        static void Main(string[] args)
        {
            int    menu;
            string input;

            do
            {
atstart:
                Console.WriteLine("1-Enter triangle dimensions");
                Console.WriteLine("2-Exit");
                input = Console.ReadLine();

                if (int.TryParse(input, out menu))
                {
                    menu = Convert.ToInt32(input);
                    switch (menu)
                    {
                    case 1:
                        int a, b, c;
                        Console.WriteLine("Enter three integer ");
begin:
                        Console.WriteLine("Enter first sides");
                        //First side
                        String firstside = Console.ReadLine();
                        int    result1   = 0;

                        if (int.TryParse(firstside, out result1))
                        {
                            a = Convert.ToInt32(firstside);
                        }
                        else
                        {
                            Console.WriteLine("Not a number");
                            goto begin;
                        }
                        //Second side
begin2:
                        Console.WriteLine("Enter second side");
                        String secondside = Console.ReadLine();
                        int    result2    = 0;

                        if (int.TryParse(secondside, out result2))
                        {
                            b = Convert.ToInt32(secondside);
                        }
                        else
                        {
                            Console.WriteLine("Not a number");
                            goto begin2;
                        }
                        //Third side
begin3:
                        Console.WriteLine("Enter third side");
                        String thirdside = Console.ReadLine();
                        int    result3   = 0;

                        if (int.TryParse(thirdside, out result3))
                        {
                            c = Convert.ToInt32(thirdside);
                        }
                        else
                        {
                            Console.WriteLine("Not a number");
                            goto begin3;
                        }

                        if ((a + b > c || b + c > a || a + c > b) && (a > 0) && (b > 0) && (c > 0))
                        {
                            Console.WriteLine("Three sides form a triangle");

                            string d = TriangleSolver.Analyze(a, b, c);
                            Console.WriteLine("Triangle is " + " " + d);
                        }
                        else
                        {
                            Console.WriteLine("Enter proper value for sides");
                            goto atstart;
                        }
                        break;

                    case 2:
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Not a number");
                    goto atstart;
                }
            } while (menu != 2);
        }
Пример #5
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;
                }
            }
        }
Пример #6
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);
        }