Ruby program to calculate trapezoid area

Views: 122   

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}"

Output:

Please enter base1 of trapezoid:
5
Please enter base2 of trapezoid:
8
Please enter height of trapezoid:
3
Area of trapezoid is: 19.5
On By