Skip to content

Instantly share code, notes, and snippets.

@kat-perreira
Created March 2, 2018 19:36
Show Gist options
  • Save kat-perreira/d832c46c71f74e9e421d71791ed0dd75 to your computer and use it in GitHub Desktop.
Save kat-perreira/d832c46c71f74e9e421d71791ed0dd75 to your computer and use it in GitHub Desktop.
Homework assignment 1 created by kaimana_Cat - https://repl.it/@kaimana_Cat/Homework-assignment-1
=begin
Practice: Write a command line program that asks the user for the year they were born,
then calculates their age in years, days, and seconds.
Tell the user how old they are in these different formats.
(Note: you'll be using 'gets' and 'puts' in this program, along with some math)
=end
# Ask year user name
puts "Please enter your name:"
name = gets.chomp
#Ask year that user is born, enter variable as yearBorn
puts "Hello " + name + ", what year were you born?"
year_born = gets.chomp.to_i
#calculate years
age_year = 2018 - year_born.to_i
#calculate years to days
age_days = age_year.to_i * 365
#calculate days to seconds
age_seconds = age_days.to_i * 86400
#output: Years, days and seconds old
print "Thank you. According to math, you are "
print age_year
puts " years old."
print "You are "
print age_days
puts " days old. "
print "You are "
print age_seconds
puts "seconds old."
#Eat a cupcake to celebrate!!! :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment