logo image

Ruby program to calculate trapezoid area

Following program shows you how to calculate trapezoid area. This program gets trapezoid base and height from user and calculates area and prints it using following formula `Area = (base1 + base2) X height /2

 puts "Please enter base1 of trapezoid:"
 trapezoidBase1 = gets.to_f
 puts "Please enter base2 of trapezoid:"
 trapezoidBase2 = gets.to_f
 puts "Please enter height of trapezoid:"
 trapezoidHeight = gets.to_f
 areaOfTrapezoid = (trapezoidBase1 + trapezoidBase2) * trapezoidHeight / 2
 puts "Area of trapezoid is: #{areaOfTrapezoid}"


Please enter base1 of trapezoid:
Please enter base2 of trapezoid:
Please enter height of trapezoid:
Area of trapezoid is: 19.5