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: 3703599 • 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 _3LineSegment
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
        
            do
            {
                Console.WriteLine("Enter Three sides value to form a triangle:");
             
                Console.Write("Enter the value for a:");
                String Result1 = Console.ReadLine();
                while (!Int32.TryParse(Result1, out a))
                {
                    Console.WriteLine("Not a valid number, Input number only!");
                    Console.Write("Enter the value for a:");
                    Result1 = Console.ReadLine();
                    Console.WriteLine(Result1);
                }
              
                Console.Write("Enter the value for b:");
                String Result2 = Console.ReadLine();
                while (!Int32.TryParse(Result2, out b))
                {
                    Console.WriteLine("Not a valid number, Input number only!");
                    Console.Write("Enter the value for b:");
                    Result2 = Console.ReadLine();
                }
             
                Console.Write("Enter the value for c:");
                String Result3 = Console.ReadLine();
                while (!Int32.TryParse(Result3, out c))
                {
                    Console.WriteLine("Not a valid number, Input number only!");
                    Console.Write("Enter the value for c:");
                    Result3 = Console.ReadLine();
                }
                            
                if ((a + b > c) && (a + c > b) && (b + c > a))
                {
                 
                    Console.WriteLine("Value of a: " + a);
                    Console.WriteLine("Value of b: " + b);
                    Console.WriteLine("Value of c: " + c);
                    Console.WriteLine("entered value can form a triangle");
                }
                else
                {
                    Console.WriteLine("entered value can not form a triangle");
                }
                Console.Write("Do you want to continue (Y/N)?");
                if(Console.ReadLine() == "n")
                {
                    System.Environment.Exit(0);

                }
            } while (Console.ReadLine() != "Y");
        

            Console.ReadKey();
        }
    }
}

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