Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class TrapezoidArea
- {
- static void Main()
- {
- double trapezoidSideA, trapezoidSideB, trapezoidHeight;
- bool inputCheck;
- Console.WriteLine("Trapezoid's area");
- Console.WriteLine("Enter value side A: ");
- inputCheck = double.TryParse(Console.ReadLine(), out trapezoidSideA) && trapezoidSideA > 0 && trapezoidSideA <= double.MaxValue;
- if (!inputCheck)
- {
- Console.WriteLine("Invalid input!\n");
- Main();
- }
- Console.WriteLine("Enter value side B: ");
- inputCheck = double.TryParse(Console.ReadLine(), out trapezoidSideB) && trapezoidSideB > 0 && trapezoidSideB <= double.MaxValue;
- if (!inputCheck)
- {
- Console.WriteLine("Invalid input!\n");
- Main();
- }
- Console.WriteLine("Enter value height H: ");
- inputCheck = double.TryParse(Console.ReadLine(), out trapezoidHeight) && trapezoidHeight > 0 && trapezoidHeight <= double.MaxValue;
- if (!inputCheck)
- {
- Console.WriteLine("Invalid input!\n");
- Main();
- }
- checked
- {
- Console.WriteLine("Result: S = 1/2 * (A + B) * H = 1/2 * ({0} + {1}) * {2} = {3}\n", trapezoidSideA, trapezoidSideB, trapezoidHeight, ((trapezoidSideA + trapezoidSideB) * trapezoidHeight) / 2);
- Main();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment