Advertisement
martyz

Geometry Calculator

Oct 6th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace GeometryCalculator
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string figure = Console.ReadLine();
  14.             if (figure == "square" || figure == "circle")
  15.             {
  16.                 GetArea(figure, double.Parse(Console.ReadLine()));
  17.             }
  18.             else
  19.             {
  20.                 GetArea(figure, double.Parse(Console.ReadLine()), double.Parse(Console.ReadLine()));
  21.             }
  22.         }
  23.  
  24.         public static void GetArea(string figure, double num1, double num2 = 42) // 42 = The answer to life the universe and everything
  25.         {
  26.            
  27.             switch (figure.ToLower())
  28.             {
  29.                 case "triangle":
  30.                     Console.WriteLine("{0:0.00}",  num1 * num2 / 2);
  31.                     break;
  32.                 case "square":
  33.                     Console.WriteLine("{0:0.00}", num1 * num1);
  34.                     break;
  35.                 case "rectangle":
  36.                     Console.WriteLine("{0:0.00}", num1 * num2);
  37.                     break;
  38.                 case "circle":
  39.                     Console.WriteLine("{0:0.00}", Math.PI * (num1 * num1));
  40.                     break;
  41.                 default:
  42.                     break;
  43.             }
  44.         }
  45.        
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement