Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

triangle

namespace TriAngle;

internal class MainClass : Program
{
        public static void Main()
        {
            var triangle = new Triangle();
            Triangle.Runner();
        }
    }
 
public class Program : TriangleItems
{
    protected class Triangle : TryExcept
    {
        private double A { get; set; }
        private double B { get; set; }
        private double C { get; set; }

        public void TriangleSides()
        {
              this.A = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("a is " + A);
            this.B = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("b is " + B);
            this.C = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("c is " + C);
        }
        
        public void Perimeter()
        {
            if (A + B > C || B + C > A || A + C > B)
            {
                var perimeter = A + B + C;
                Console.WriteLine("Triangle's perimeter is " + perimeter);
            }
            else if (A == 0 || B == 0 || C == 0)
            {
                Console.WriteLine("Triangle's side can't be zero");
            }
            else
            {
                Console.WriteLine("Sorry! But such triangle doesn't exist!");
            }
        }  
        
        public void Area()
        {
           if (A + B > C || B + C > A || A + C > B)
            {
                var s = (A + B + C) / 2;
                var area = Math.Sqrt(s * (s - A) * (s - B) * (s - C));
                Console.WriteLine("Triangle's area is  " + area);
            }
            else if (A == 0 || B == 0 || C == 0)
            {
                Console.WriteLine("Triangle's side can't be zero");
            }
            else
            {
                Console.WriteLine("Sorry! But such triangle doesn't exist!");
            }
        }
        
        public static DateTime Runner()
        {
            while (true)
            {
                Console.WriteLine("Welcome to Triangle's calculator!");
                Console.WriteLine("Press 1 for start!");

                var input1 = Convert.ToInt32(Console.ReadLine());

                if (input1 == 1)
                {
                    StartProgram = DateTime.Now;
                }
                else
                {
                    throw (new FormatException("You must start program with '1' "));
                }

                Area_try_Except();
                Perimeter_try_Except();

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

                if (input1 == 2)
                {
                    StopProgram = DateTime.Now;
                }
                else
                {
                    throw (new FormatException("You must stop program with '2' "));
                }
            }
        }
    }
}
 
public class TryExcept : Program
{
    protected static void Area_try_Except()
    {
        try
        {
            var triangle = new Triangle();
            Console.WriteLine("Insert values for triangle's area operation : ");
            triangle.TriangleSides();
            triangle.Area();
        }
        catch
        {
            throw new FormatException("Looks like something went wrong.Triangle's side must be a number!");
        }
    }
  
    protected static void Perimeter_try_Except()
    {
        try
        {
            var triangle = new Triangle();
                Console.WriteLine("You can also calculate triangle's perimeter.It can be same values as before or different.It doesn't affect program functionality!");
                Console.WriteLine("Before calculate perimeter, please enter values again : ");
                triangle.TriangleSides();
                triangle.Perimeter();
        }
        catch
        {
            throw new FormatException("Looks like something went wrong.Triangle's side must be a number!");
        }
    }
}
 
public class TriangleItems
{
    protected static DateTime StartProgram { get; set; }
    protected static DateTime StopProgram { get; set; }

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

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

Triangle

 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

triangle

A polygon with three edges. Triangles are always convex.
Comment

Triangle

/***************************************************
 * Author    : CS Developers
 * Author URI: https://www.comscidev.com
 * Facebook  : https://www.facebook.com/CSDevelopers
 ***************************************************/

#include <stdio.h>
 
int main()
{
    float base;
    float height;
 
    printf("
Input value of base : ");
    scanf("%f", &base);
 
    printf("Input value of height : ");
    scanf("%f", &height);
      
    printf("
Area of a Triangle is %.2f 

", 0.5 * base * height);
 
    return 0;
}
Comment

triangle

its not real
Comment

PREVIOUS NEXT
Code Example
Csharp :: math.pow in C# using loop 
Csharp :: unity animation length 
Csharp :: c# double 
Csharp :: how to filter a list in c# 
Csharp :: c# exit foreach 
Csharp :: what dotnet command does 
Csharp :: action c# 
Csharp :: c# sequential struct with fixed array size 
Csharp :: Storing Data within your TileEntity 
Csharp :: rotate skybox on x axis unity 
Csharp :: cefsharp print 
Csharp :: Unity Input Key Message 
Csharp :: list equals in order c# 
Csharp :: Read csv file into wpf C# 
Csharp :: no cameras rendering unity 
Csharp :: c# namespace name form1 could not be found 
Csharp :: conflictingactionsresolver as a workaround 
Csharp :: mesh decimate pyvista 
Csharp :: c# how to disable a event 
Csharp :: c# check value at design time 
Csharp :: index sort 
Csharp :: c# insert from with bind array 
Csharp :: c# Showing a hidden WPF window 
Csharp :: how to get src value from img tag in c# 
Csharp :: telerik raddatepicker default date today wpf 
Csharp :: how to create an initialized jtoken c# 
Csharp :: unknown discriminator value mongodb 
Csharp :: how to check that a gameobject touches a colour in unity c# 
Csharp :: vb.net check operating system 
Csharp :: c# create monochrome bitmap 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =