Beispiel #1
0
        static void Main(string[] args)
        {
            try
            {
                int  firstDimension  = 0;
                int  secondDimension = 0;
                int  thirdDimension  = 0;
                bool exit            = false;

                Console.Clear();
                string notice = "";
                ShowMenu();

                while (!exit)
                {
                    Console.Write("Menu: ");
                    string reply = Console.ReadLine();
                    switch (reply)
                    {
                    case "1":
                        Console.WriteLine("Please enter the length of three dimensions of a triangle");
                        firstDimension  = ValidateInt(firstDimension, "First Dimension");
                        secondDimension = ValidateInt(secondDimension, "Second Dimension");
                        thirdDimension  = ValidateInt(thirdDimension, "Third Dimension");
                        notice          = $"Successfully entered {firstDimension}, {secondDimension}, and {thirdDimension}\n" +
                                          TriangleSolver.Analyze(firstDimension, secondDimension, thirdDimension);
                        Console.Clear();
                        break;

                    case "2":
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadLine();
                        exit = true;
                        break;

                    default:
                        notice = "Please select 1 or 2";
                        break;
                    }
                    Console.Clear();
                    ShowMenu();
                    if (notice != "")
                    {
                        Console.WriteLine("* " + notice);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                ShowMenu();
            }
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     do
     {
         //show the menu and get the user input
         int input = GetUserInput();
         if (input == menu.Length)
         {
             Environment.Exit(0);
         }
         else
         {
             //get the dimensions of the triangle
             int[]  dimensions = GetDimensions();
             string result     = TriangleSolver.Analyze(dimensions[0], dimensions[1], dimensions[2]);
             Console.Write("\n\n" + result);
         }
     } while (true);
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            bool isValidChoice = false;

            while (isValidChoice == false)
            {
                Console.WriteLine("Press 1 or 2 ");
                Console.WriteLine("1. Enter triangle dimensions.");
                Console.WriteLine("2. Exit");
                string choice = Console.ReadLine();
                if (choice == "1")
                {
                    isValidChoice = true;
                    int sideA = validateTriangleSideA();
                    int sideB = validateTriangleSideB();
                    int sideC = validateTriangleSideC();

                    string message = TriangleSolver.Analyze(sideA, sideB, sideC);
                    Console.WriteLine(message);
                    Console.WriteLine("");
                    Console.WriteLine("Press any key to exit the program");
                    Console.ReadKey();
                }
                else if (choice == "2")
                {
                    isValidChoice = true;
                    Console.WriteLine("Program Now exiting");
                    Environment.Exit(0);
                }
                else
                {
                    Console.WriteLine("This is not valid input, Please Enter Valid number");
                }
                Console.WriteLine("");
            }
        }
Beispiel #4
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 #5
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);
            }
        }