static void Main(string[] args) { string cont; string userInput = string.Empty; bool Validmenuselect = false; string resultString = string.Empty; while (Validmenuselect == false) { do { Console.WriteLine("1.Enter the triangle dimensions"); Console.WriteLine("2.Exit"); Console.WriteLine("Please select an option by entering a valid number from the ablove list"); userInput = Console.ReadLine(); if (userInput != "1" && userInput != "2") { Console.WriteLine("Please enter a Valid option"); } else if (userInput == "2") { Console.WriteLine("Exiting from the program"); System.Environment.Exit(0); } else { Validmenuselect = true; string side1, side2, side3; int sideint1, sideint2, sideint3; Console.WriteLine("Enter the first side"); side1 = Console.ReadLine(); Console.WriteLine("Enter the second side"); side2 = Console.ReadLine(); Console.WriteLine("Enter the third side"); side3 = Console.ReadLine(); if ((int.TryParse(side1, out sideint1)) && (int.TryParse(side2, out sideint2)) && (int.TryParse(side3, out sideint3)) && (sideint1 > 0) && (sideint2 > 0) && (sideint3 > 0)) { Console.WriteLine(TriangleSolver.Analyze(sideint1, sideint2, sideint3)); } else { Console.WriteLine("The given inputs doesnot form a triangle!!"); } } Console.WriteLine("Do you want to continue?:(Y/N)"); cont = Console.ReadLine(); } while ((cont == "Y") || (cont == "y")); } }
static void Main(string[] args) { int input; string inputString; //showing selection options do { Console.WriteLine("1-Enter triangle dimensions"); Console.WriteLine("2-Exit"); Console.WriteLine("Enter number: "); inputString = Console.ReadLine(); } while (!(int.TryParse(inputString, out input)) || input < 0 || input > 3); //taking inputs if (input == 1) { Console.WriteLine("Enter number1"); int num1 = int.Parse(Console.ReadLine()); Console.WriteLine("Enter number2"); int num2 = int.Parse(Console.ReadLine()); Console.WriteLine("Enter number3"); int num3 = int.Parse(Console.ReadLine()); string output = TriangleSolver.Analyze(num1, num2, num3); Console.WriteLine(output); } //for exiting program else { Environment.Exit(-1); } Console.ReadLine(); }
static void Main(string[] args) { while (true) { Console.WriteLine("1.Enter triangle dimensions"); Console.WriteLine("2.Exit"); String menu = Console.ReadLine(); int choice; bool correctInput = Int32.TryParse(menu, out choice); if (correctInput == true) { switch (choice) { case 1: int a, b, c; Console.WriteLine("Enter three integers: "); Console.WriteLine("Enter the first integer: "); a = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the second integer: "); b = int.Parse(Console.ReadLine()); Console.WriteLine("Enter the third integer: "); c = int.Parse(Console.ReadLine()); string result = TriangleSolver.Analyze(a, b, c); Console.WriteLine(result); break; case 2: System.Environment.Exit(0); break; default: break; } } } }
// Main method public static void Main() { // Exception Handling - If entering double value instead of integers. try { // Checks the condition for the infinity loop. while (true) { // Prints the line Console.WriteLine($"1. Enter Triangle Dimensions "); // Prints the line Console.WriteLine($"2. Exit"); // Initialize the variable for the user input. // Node A: int i = int.Parse(Console.ReadLine()); // Condition for the infinity loop. // If user enters input value as '1' then the condition satisfies and performs the condition. // Node B: if (i == 1) { // Prints the line. // Node C; Console.WriteLine($"Enter the side1 of the triangle "); // User can input side1 of the triangle value. // Node D: int a = int.Parse(Console.ReadLine()); // Prints the line // Node E: Console.WriteLine($"Enter the side2 of the triangle"); // User can input side2 of the triangle value. // Node F: int b = int.Parse(Console.ReadLine()); // Prints the line // Node G: Console.WriteLine($"Enter the side3 of the triangle "); // User can input side3 of the triangle value. // Node H: int c = int.Parse(Console.ReadLine()); // Call the Analyze method to print which triangle satisfies the given value and displays the kind of the triangle accordingly. // Node I: Console.WriteLine(TriangleSolver.Analyze(a, b, c)); // Procedure stops break; } // Exit // Node S: else if (i == 2) { break; } } } // Exception Handling and prints the reason about what's wrong. catch { Console.WriteLine($"Dimensions entered are incorrect"); } }
static void Main(string[] args) { bool rpt = true; while (rpt) { try { Console.WriteLine("1. Enter triangle dimensions"); Console.WriteLine("2. Exit"); int input = int.Parse(Console.ReadLine()); switch (input) { case 1: Console.WriteLine("Please Enter Three Sides Triangle\n"); Console.WriteLine("Check it Form a triangle or not"); Console.WriteLine("triangle is scalene, isosceles or equilateral\n"); int s1 = 0; int s2 = 0; int s3 = 0; Console.Write("Enter Value of Side 1 for Triangle: "); s1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Value of Side 2 for Triangle: "); s2 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Value of Side 3 for Triangle: "); s3 = Convert.ToInt32(Console.ReadLine()); if ((TriangleSolver.checkValidity(s1, s2, s2)) == 1) { Console.Write("Valid triangle\n"); string res = TriangleSolver.Analyze(s1, s2, s3); Console.WriteLine(res); } else { Console.Write("Invalid triangle\n"); } break; case 2: Console.WriteLine("Thank you.\n"); System.Environment.Exit(0); rpt = false; break; default: Console.WriteLine("Wrong input! Enter 1 or 2 only \n "); continue; } } catch (Exception) { Console.WriteLine("Please enter correct input"); }; } }
public void Analyze_ifSumOfTwoSidesIsEqualToThirdSide_expectInvalidTriangle() { Assert.AreEqual("Given numbers CAN NOT be sides of a Triangle.", TriangleSolver.Analyze(12, 7, 5)); }
public void Analyze_ifTwoSidesHoldMinBoundryValuesThirdSideHoldMaxValue_expectInvalidTriangle() { Assert.AreEqual("Given numbers CAN NOT be sides of a Triangle.", TriangleSolver.Analyze(1, 1, 2147483647)); }
public void Analyze_ifTwoSidesAreEqualAndHoldBoundryValues_expectIsosceles() { Assert.AreEqual("Given numbers ARE sides of an ISOSCELES Triangle.", TriangleSolver.Analyze(2147483647, 2147483647, 15)); }
public void Analyze_ifThreeSidesAreEqualAndHoldBoundryValues_expectEquilateral() { Assert.AreEqual("Given numbers ARE sides of an EQUILATERAL Triangle.", TriangleSolver.Analyze(2147483647, 2147483647, 2147483647)); }
public void Analyze_ifSumOfTwoSidesIsLessThanThird_expectInvalidTriangle() { Assert.AreEqual("Given numbers CAN NOT be sides of a Triangle.", TriangleSolver.Analyze(10, 5, 1)); }
public void Analyze_ifNoSideEqual_expectScalene() { Assert.AreEqual("Given numbers ARE sides of an SCALENE Triangle.", TriangleSolver.Analyze(5, 7, 10)); }
public void Analyze_ifTwoSidesAreEqual_expectIsosceles() { Assert.AreEqual("Given numbers ARE sides of an ISOSCELES Triangle.", TriangleSolver.Analyze(10, 10, 15)); }
public void Analyze_ifThreeSidesAreEqual_expectEquilateral() { Assert.AreEqual("Given numbers ARE sides of an EQUILATERAL Triangle.", TriangleSolver.Analyze(5, 5, 5)); }