private static void Main() { WriteLine("1. Matrix task"); WriteLine("2. Triangle task"); WriteLine("0. Exit"); bool showOptions = true; while (showOptions) { Write("\nChose option: "); switch (ReadLine()) { case "0": showOptions = false; break; case "1": ShowMatrixTaskSolution(); break; case "2": TTriangle t = CreateTriangle(); if (t != null) { PrintTrianglePerimeter(t); PrintTriangleArea(t); } break; default: WriteLine("Invalid option selected"); break; } } }
private static TTriangle CreateTriangle() { int[] triangleSides = GetTriangleSides(); TTriangle triangle; try { if (triangleSides.Length == 3) { triangle = new TTriangle( triangleSides[0], triangleSides[1], triangleSides[2]); } else if (triangleSides.Length == 2) { triangle = new TTriangle( triangleSides[0], triangleSides[1]); } else if (triangleSides.Length == 1) { triangle = new TTriangle(triangleSides[0], 1); } else { triangle = new TTriangle(); } return(triangle); } catch (Exception e) { WriteLine(e); } return(null); }
private static void PrintTrianglePerimeter(TTriangle t) => WriteLine("Triangle perimeter: {0}", t.GetPerimeter(t.Side1, t.Side2, t.Side3));
private static void PrintTriangleArea(TTriangle t) => WriteLine("Triangle area: {0}", t.GetArea(t.Side1, t.Side2, t.Side3));