Ruby program to take birth year and tells age

Views: 115   

Following program shows you how to take birth year and tells age.
In this program we get birth year from user and tells their age using Date.today.year - birthYear

require 'date'
puts "Please enter your date of birth:"
birthYear = Integer(gets.chomp)
age = Date.today.year - birthYear
puts "Your age is #{age}"

Output:

Please enter your date of birth:
 1960
Your age is 58
On By