User:Whoblah/Ruby/Math
Jump to navigation
Jump to search
Solutions to simple math problems using Ruby
#!/usr/bin/env ruby ## Area of a circle def area_circle(radius) return Math::PI * (radius)**2 end puts "What is the radius of the circle?" input = gets.chomp.to_f area = area_circle(input).to_f puts "The radius of the circle is #{input} units" puts "The area of the circle is #{area} square units"
#!/usr/bin/env ruby ## Area of an octagon def area_octagon(radius) return 2 * (radius)**2 * Math::sqrt(2) end puts "What is the radius of the octagon?" input = gets.chomp.to_f area = area_octagon(input).to_f puts "The radius of the octagon is {#input} units" puts "The area of the octagon is {#area} square units"