Guest User

Untitled

a guest
Jul 9th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #Day 1 Exercises Problem #4
  2.  
  3. #Create a program that accepts input from the user and outputs a bio
  4. #with that information
  5. #Use up to five different attributes about the person to
  6. #populate the bio
  7.  
  8.  
  9. print "Name: "
  10. name = gets.chomp
  11.  
  12. puts "Date of birth:"
  13.  
  14. print "Month: "
  15. bd_month_name = gets.chomp
  16. bd_month = bd_month_name.downcase[0..2]
  17. print "Day: "
  18. bd_day = gets.chomp.to_i
  19.  
  20. print "Year: "
  21. bd_year = gets.chomp.to_i
  22.  
  23. print "Occupation: "
  24. occupation = gets.chomp
  25.  
  26. #Output should consist of a paragraph of output created from the
  27. #users input
  28.  
  29. current_time = Time.now
  30.  
  31. birth_date = Time.new(bd_year, bd_month, bd_day)
  32.  
  33. age = (current_time.year - birth_date.year).to_i
  34.  
  35. current_year_birthday = Time.new(Time.now.year, birth_date.month, birth_date.day)
  36. if birth_date.month < current_time.month && birth_date.day < current_time.day
  37. days_til_bday = "#{(current_year_birthday - current_time + 31536000)/86400}"
  38.  
  39. elsif birth_date.month == current_time.month && birth_date.day < current_time.day
  40. days_til_bday = "#{(current_year_birthday - current_time + 31536000)/86400}"
  41.  
  42. elsif birth_date.month == current_time.month && birth_date.day > current_time.day
  43. days_til_bday = "#{(current_year_birthday - current_time)/86400}"
  44.  
  45. elsif birth_date.month > current_time.month
  46. days_til_bday = "#{(current_year_birthday- current_time)/86400}"
  47.  
  48. elsif birth_date == current_time
  49. puts "Today is your Birthday, Happy Birthday!"
  50. end
  51. puts
  52. puts
  53. puts "#{name.capitalize} is a(n) #{occupation} who was born on #{bd_month_name} #{bd_day}, #{bd_year}."
  54. puts "They work as a(n) #{occupation.capitalize}."
  55. 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