Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help writing a c# program. Prompt the user for the length of three line segments

ID: 3703925 • Letter: H

Question

Help writing a c# program.

Prompt the user for the length of three line segments as integers. If the three lines could form a triangle, print the integers and a message indicating they form a triangle. Use a state-controlled loop to allow users to enter as many different combinations as they want.

HINT: Three sides can make a triangle if the sum of any two sides is greater than the third side. For instance, the sides {3, 4, 5} can make a triangle. However, the group {2, 3, 10} is not a valid triangle combination.

Explanation / Answer

using System;

namespace MyTriangle

{

    public class Triangle

    {

        public static void Main(string[] args)

        {

            Console.WriteLine("Enter first side : ");

            int a = Convert.ToInt32(Console.ReadLine());

           

            Console.WriteLine("Enter second side : ");

            int b = Convert.ToInt32(Console.ReadLine());

           

            Console.WriteLine("Enter third side : ");

            int c = Convert.ToInt32(Console.ReadLine());

            // if the sum of any two sides is greater than the third side

            if( ( a + b > c ) && ( a + c > b ) && ( b + c > a ) )

                Console.Write("It forms a Triangle.");

            else

                Console.Write("It doesn't form a Triangle.");

        }

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote