lmarkov

Trapezoid Area

Nov 26th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2.  
  3. class TrapezoidArea
  4. {
  5.     static void Main()
  6.     {
  7.         double trapezoidSideA, trapezoidSideB, trapezoidHeight;
  8.         bool inputCheck;
  9.  
  10.         Console.WriteLine("Trapezoid's area");
  11.  
  12.         Console.WriteLine("Enter value side A: ");
  13.         inputCheck = double.TryParse(Console.ReadLine(), out trapezoidSideA) && trapezoidSideA > 0 && trapezoidSideA <= double.MaxValue;
  14.         if (!inputCheck)
  15.         {
  16.             Console.WriteLine("Invalid input!\n");
  17.             Main();
  18.         }
  19.        
  20.         Console.WriteLine("Enter value side B: ");
  21.         inputCheck = double.TryParse(Console.ReadLine(), out trapezoidSideB) && trapezoidSideB > 0 && trapezoidSideB <= double.MaxValue;
  22.         if (!inputCheck)
  23.         {
  24.             Console.WriteLine("Invalid input!\n");
  25.             Main();
  26.         }
  27.  
  28.         Console.WriteLine("Enter value height H: ");
  29.         inputCheck = double.TryParse(Console.ReadLine(), out trapezoidHeight) && trapezoidHeight > 0 && trapezoidHeight <= double.MaxValue;
  30.         if (!inputCheck)
  31.         {
  32.             Console.WriteLine("Invalid input!\n");
  33.             Main();
  34.         }
  35.         checked
  36.         {            
  37.             Console.WriteLine("Result: S = 1/2 * (A + B) * H = 1/2 * ({0} + {1}) * {2} = {3}\n", trapezoidSideA, trapezoidSideB, trapezoidHeight, ((trapezoidSideA + trapezoidSideB) * trapezoidHeight) / 2);
  38.             Main();
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment