Advertisement
MarinParov

Switch Case CSharp

Feb 16th, 2019
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 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 _7._5_Square_of_a_FigureType
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             String FigureType = Console.ReadLine();
  14.             switch (FigureType)
  15.             {
  16.                 case "square":
  17.                     {
  18.                         double a = Double.Parse(Console.ReadLine());
  19.                         double area = Math.Pow(a, 2);
  20.                         Console.WriteLine(Math.Round(area, 2));
  21.                         break;
  22.                     }
  23.  
  24.                 case "rectangle":
  25.                     {
  26.                         double a = Double.Parse(Console.ReadLine());
  27.                         double b = Double.Parse(Console.ReadLine());
  28.                         double area = a * b;
  29.                         Console.WriteLine(Math.Round(area, 2));
  30.                         break;
  31.                     }
  32.                 case "circle":
  33.                     {
  34.                         double r = Double.Parse(Console.ReadLine());
  35.                         double area = Math.PI * Math.Pow(r, 2);
  36.                         Console.WriteLine(Math.Round(area, 3));
  37.                         break;
  38.                     }
  39.                 case "triangle":
  40.                     {
  41.                         double a = Double.Parse(Console.ReadLine());
  42.                         double h = Double.Parse(Console.ReadLine());
  43.                         double area = (a * h) / 2;
  44.                         Console.WriteLine(Math.Round(area, 2));
  45.                         break;
  46.                     }
  47.             }
  48.  
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement