Last active
December 30, 2015 13:09
-
-
Save damianesteban/7834117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write a program in Ruby that tells you how old I am | |
# if I am 979000000 seconds old. Display the result as a floating point (decimal) number to two | |
# decimal places (for example, 17.23). Note: To format the output to say 2 decimal | |
# places, we can use the Kernel's format method. For example, if x = 45.5678 then format("%.2f", x) | |
# will return the string 45.57 | |
def seconds_to_years(seconds) | |
seconds_in_year = 31536000 | |
age = seconds.to_f / seconds_in_year.to_f | |
printf "You are %.2f years old.", age | |
end | |
seconds_to_years(979000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment