Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Triangle perimeter

 namespace TriangleCalc; 
 public class Program
 {
     private double A { get; set; }
     private double B { get; set; }
     private double C { get; set; }
     public void Triangle()
     {
         try
         {
             this.A = Convert.ToDouble(Console.ReadLine());
             Console.WriteLine("a is " + A);
             this.B = Convert.ToDouble(Console.ReadLine());
             Console.WriteLine("b is " + B);
             this.C = Convert.ToDouble(Console.ReadLine());
             Console.WriteLine("c is " + C);
         }  catch
         {
             throw (new Exception("Triangle's side must be a number"));
         }
     }
     
     public void Area()
     {
             if (A + B > C && B + C > A && A + C >B )  
             {
                 var s  = (A+B+C)/2;
                 var result = Math.Sqrt(s * (s - A) * (s - B) * (s - C));
                 Console.WriteLine("The area is " + result );
             }
             else
             {
                 Console.WriteLine("Result is NaN");
             }
     }
     
     public void Perimeter()
     {
         if (A + B > C && A + C > B && B + C > A)
         {
             var perimeter = A + B + C;
             Console.WriteLine("The perimeter is " + perimeter);
         }
         else
         {
             Console.WriteLine("Such triangle doesn't exist");
         }
     } 
 }

public class Runner : Program
{
    public static void Main(string[] args)
    {
        while (true)
        {
            Console.WriteLine("1-Start
2-Stop");
            var input1 = Convert.ToInt32(Console.ReadLine());

            if (input1 == 1)
            {
                var startProgram = Triangleİtems.Start;
            }
            else
            {
                throw (new Exception("Program must start with 1"));
            }

            var triangle = new Program();
            triangle.Triangle();
            triangle.Area();
            triangle.Perimeter();

            Console.WriteLine("You can end program with 2");
            input1 = Convert.ToInt32(Console.ReadLine());

            if (input1 == 2)
            {
                var stopProgram = Triangleİtems.Stop;
            }

            else
            {
                throw (new Exception("Program must stop with 2"));
            }
        }
    }
}

public static class Triangleİtems
{
    public static DateTime Start;
    public static DateTime Stop;

    public static DateTime StartProgram()
    {
        Start = DateTime.Now;
        return Start;
    }

    public static DateTime StopProgram()
    {
        Stop = DateTime.Now;
        return Stop;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: entity framework id not auto increment 
Csharp :: How can I get my stripe customer ID? 
Csharp :: c# copy an object 
Csharp :: Proxy in Config 
Csharp :: linq where condition c# 
Csharp :: what are delegates and how to use them c# 
Csharp :: c# convert datetime to timespan 
Csharp :: round image unity 
Csharp :: addssdawsdawdsdawasdawasdawdswsddsdawssd 
Csharp :: muovere un elemento in c# 
Csharp :: shuffle array c# 
Csharp :: mongodb custom IIdGenerator 
Csharp :: c sharp xml prettier 
Csharp :: index list c# 
Csharp :: empty int array c# 
Csharp :: scale min max to 0 1 
Csharp :: c# entity mvc get user from razor layout 
Csharp :: VSIX Project Context Menu 
Csharp :: how to if button pressed do something in c# 
Csharp :: c# Unit Test IDbContextFactory 
Csharp :: c# simplified if statement 
Csharp :: negative indexing in c# 
Csharp :: Microsoft.ACE.OLEDB.12.0 c# excel first sheet 
Csharp :: hur delar man upp en e post på string c# 
Csharp :: IEqualityComparer gethashcode strings c# 
Csharp :: creating an object 
Csharp :: How to fill text with 2 different color/texture 
Csharp :: visibility bound to radio button wpf 
Csharp :: set windows theme in c# 
Csharp :: call Textboxfor in cs 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =