예제 #1
0
        ///<summary>
        //Reading the 3 angles of a triangle, deciding whether the triangle is valid, and printing equilateral, isosceles or scalene based
        ///</summary>
        public static void CalculateTriangle()
        {
            float baseAngle1 = 0, baseAngle2 = 0, vertexAngle = 0, sum;

            UserInputValidation.ValidateUserInputRadius(ref baseAngle1, "Enter the first base angle:");
            UserInputValidation.ValidateUserInputRadius(ref baseAngle2, "Enter the second base angle:");
            UserInputValidation.ValidateUserInputRadius(ref vertexAngle, "Enter the vertex angle:");

            // Calculate the sum of all angles of triangle
            sum = baseAngle1 + baseAngle2 + vertexAngle;

            // Check whether sum=180 then its a valid triangle otherwise not
            if (sum == 180)
            {
                Console.WriteLine("The triangle is valid.");
                //Check whether the triangle is equilateral
                if (baseAngle1 == 60 && baseAngle2 == 60 && vertexAngle == 60)
                {
                    Console.WriteLine("The triangle is equilateral.");
                }
                else if (baseAngle1 == baseAngle2 || baseAngle2 == vertexAngle || baseAngle1 == vertexAngle)
                {
                    Console.WriteLine("The triangle is an isosceles.");
                }
                else
                {
                    Console.WriteLine("The triangle is scalene based.");
                }
            }
            else
            {
                Console.WriteLine("The triangle is not valid.");
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            int option = 0;

            do
            {
                ChooseOption(ref option);
                switch (option)
                {
                case 1:
                    float circleRadius = 0;
                    UserInputValidation.ValidateUserInputRadius(ref circleRadius, "Enter the radius of the circle");
                    Area(circleRadius);
                    break;

                case 2:
                    float widthOfTheRectangle = 0;
                    UserInputValidation.ValidateUserInput(ref widthOfTheRectangle, "Enter the width of the rectangle");
                    float heightOfTheRectangle = 0;
                    UserInputValidation.ValidateUserInput(ref heightOfTheRectangle, "Enter the height of the rectangle");
                    AreaRectangle(widthOfTheRectangle, heightOfTheRectangle);
                    break;

                case 3:
                    float cylinderRadius = 0;
                    UserInputValidation.ValidateUserInputRadius(ref cylinderRadius, "Enter the radius of the cylinder");
                    float cylinderHeight = 0;
                    UserInputValidation.ValidateUserInput(ref cylinderHeight, "Enter the height of the cylinder");
                    Area(cylinderRadius, cylinderHeight);
                    break;
                }
            } while (option != 4);
        }