Convert Cat's Age to Human Years using Ruby

Use you may use the following simple Ruby script to convert a cat's age to human years.

Convert Cat's Age to Human Years using Ruby
Photo by Michael Sum / Unsplash

Use you may use the following simple Ruby script to convert a cat's age to human years.

cat_age = 5 # replace with the actual age of your cat
human_age = 0

if cat_age == 1
  human_age = 15
elsif cat_age == 2
  human_age = 24
else
  human_age = 24 + (cat_age - 2) * 4
end

puts "A #{cat_age}-year-old cat in human years is #{human_age}."

Notes

  • If the cat's age is 1, the script sets the human age to 15.
  • If the cat's age is 2, the script sets the human age to 24.
  • If the cat's age is greater than 2, the script uses the general formula of multiplying each cat year by 4 to get the equivalent human years.