ellapt

3.8.TrapezoidArea

Dec 14th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. using System;
  2.  
  3. class TrapezoidArea
  4. {
  5. static void Main()
  6. {
  7. Console.WriteLine("Calculate trapezoid's area by given sides a and b and height h.");
  8. Console.Write("Please, enter side a in mm: ");
  9. string inputFloat = Console.ReadLine();
  10. float aSide, bSide, hHeight; // sides and height of the trapezoid
  11. float calcArea; // result - calculated trapezoid's area
  12.  
  13. if (float.TryParse(inputFloat, out aSide))
  14. {
  15. Console.Write("Please, enter side b in mm: ");
  16. inputFloat = Console.ReadLine();
  17. if (float.TryParse(inputFloat, out bSide))
  18. {
  19. Console.Write("Please, enter height in mm: ");
  20. inputFloat = Console.ReadLine();
  21. if (float.TryParse(inputFloat, out hHeight))
  22. {
  23. calcArea = ((aSide + bSide) * hHeight) / 2;
  24. if (calcArea <= 0)
  25. {
  26. Console.WriteLine("Not a valid input!");
  27. }
  28. else
  29. {
  30. Console.WriteLine("The area of the trapezoid is {0}mm", calcArea);
  31. }
  32. }
  33. else
  34. {
  35. Console.WriteLine("Not a valid input!");
  36. }
  37. }
  38. else
  39. {
  40. Console.WriteLine("Not a valid input!");
  41. }
  42. }
  43. else
  44. {
  45. Console.WriteLine("Not a valid input!");
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment