Advertisement
bacco

Geometry Calculator

May 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using System;
  2.  
  3. namespace GeometryCalculator
  4. {
  5.     class MainClass
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             string typeOfFigure = Console.ReadLine();
  10.             double sideWidthRadius = double.Parse(Console.ReadLine());
  11.             double height = 0.0;
  12.  
  13.             if (typeOfFigure == "triangle" || typeOfFigure == "rectangle")
  14.             {
  15.                  height = double.Parse(Console.ReadLine());
  16.             }
  17.  
  18.             double area = 0.0;
  19.  
  20.             switch (typeOfFigure)
  21.             {
  22.                 case "triangle":
  23.                     area = retrnAreaTriangle(sideWidthRadius,
  24.                                              height);
  25.                     break;
  26.                 case "square":
  27.                     area = retrnAreaSquare(sideWidthRadius);
  28.                     break;
  29.                 case "rectangle":
  30.                     area = retrnAreaRectangle(sideWidthRadius,
  31.                                              height);
  32.                     break;
  33.                 default:
  34.                     area = retrnAreaCircle(sideWidthRadius);
  35.                     break;
  36.             }
  37.             Console.WriteLine($"{area:f2}");
  38.         }
  39.  
  40.         static double retrnAreaTriangle(double sideWidthRadius,
  41.                                         double height)
  42.         {
  43.             double area = sideWidthRadius * height / 2;
  44.             return area;
  45.         }
  46.  
  47.         static double retrnAreaSquare(double sideWidthRadius)
  48.         {
  49.             double area = sideWidthRadius * sideWidthRadius;
  50.             return area;
  51.         }
  52.  
  53.         static double retrnAreaRectangle(double sideWidthRadius,
  54.                                         double height)
  55.         {
  56.             double area = sideWidthRadius * height;
  57.             return area;
  58.         }
  59.  
  60.         static double retrnAreaCircle(double sideWidthRadius)
  61.         {
  62.             double area = Math.PI * sideWidthRadius * sideWidthRadius;
  63.             return area;
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement