Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Day 1 Exercises Problem #4
- #Create a program that accepts input from the user and outputs a bio
- #with that information
- #Use up to five different attributes about the person to
- #populate the bio
- print "Name: "
- name = gets.chomp
- puts "Date of birth:"
- print "Month: "
- bd_month_name = gets.chomp
- bd_month = bd_month_name.downcase[0..2]
- print "Day: "
- bd_day = gets.chomp.to_i
- print "Year: "
- bd_year = gets.chomp.to_i
- print "Occupation: "
- occupation = gets.chomp
- #Output should consist of a paragraph of output created from the
- #users input
- current_time = Time.now
- birth_date = Time.new(bd_year, bd_month, bd_day)
- age = (current_time.year - birth_date.year).to_i
- current_year_birthday = Time.new(Time.now.year, birth_date.month, birth_date.day)
- if birth_date.month < current_time.month && birth_date.day < current_time.day
- days_til_bday = "#{(current_year_birthday - current_time + 31536000)/86400}"
- elsif birth_date.month == current_time.month && birth_date.day < current_time.day
- days_til_bday = "#{(current_year_birthday - current_time + 31536000)/86400}"
- elsif birth_date.month == current_time.month && birth_date.day > current_time.day
- days_til_bday = "#{(current_year_birthday - current_time)/86400}"
- elsif birth_date.month > current_time.month
- days_til_bday = "#{(current_year_birthday- current_time)/86400}"
- elsif birth_date == current_time
- puts "Today is your Birthday, Happy Birthday!"
- end
- puts
- puts
- puts "#{name.capitalize} is a(n) #{occupation} who was born on #{bd_month_name} #{bd_day}, #{bd_year}."
- puts "They work as a(n) #{occupation.capitalize}."
- puts "#{name.capitalize} is #{age} years old and it is #{days_til_bday.to_i} days til #{name}'s Birthday."
Add Comment
Please, Sign In to add comment