Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Part 1
- require 'date'
- #This function tells you how many hours are in a year
- def hoursinyear
- hours = 24*365
- return 'There are ' + hours.to_s + ' hours in one year'
- end
- #This function tells you how many minutes are in a decade
- def minutesindeacde
- minutes = 60*24*365*10
- return 'There are ' + minutes.to_s + ' minutes in one decade'
- end
- #This function gets a users age and then converts their age into seconds
- def ageinseconds
- puts 'Please enter your age in years:'
- STDOUT.flush
- age = gets.chomp.to_i
- today = Date.today.to_time.to_i
- seconds = age*24*3600*365 + today
- return 'You are ' + seconds.to_s + ' seconds old'
- end
- #This function calculates how many chocolates you hope to eat in your life (assumes lifespan of 80 years)
- def chocolates
- puts 'Pleae enter how many chocolates, on average, you eat a week?'
- STDOUT.flush
- chocolate = gets.chomp.to_i
- totalcandy = chocolate*52*80
- return 'You will eat ' + totalcandy.to_s + ' chocolates in your life'
- end
- #Print responses
- puts hoursinyear
- puts minutesindeacde
- puts ageinseconds
- puts chocolates
- Part 2
- #This function greets the user with their name
- def username
- puts 'Please enter your first name:'
- STDOUT.flush
- firstname = gets.chomp
- puts 'Please enter your middle name:'
- STDOUT.flush
- middlename = gets.chomp
- puts 'Please enter your last name:'
- STDOUT.flush
- lastname = gets.chomp
- return 'Your full name is ' + firstname + ' ' + middlename + ' ' + lastname + '. Nice to meet you!'
- end
- #Favorite number function
- def favnumber
- puts 'Please enter your favorite number:'
- STDOUT.flush
- number = gets.chomp.to_i
- return 'Although ' + number.to_s + ' is a pretty good number. I think you may like ' + (number+1).to_s + ' more since it is harder, better, faster, and stronger (as a number of coarse!)'
- end
- puts username
- puts favnumber
- Part 3
- def angryboss
- puts 'Measly employee, what do you want!'
- STDOUT.flush
- res = gets.chomp
- return 'WHADDAYA MEAN "' + res + '"?!? YOUR"RE FIRED!!'
- end
- puts angryboss
Advertisement
Add Comment
Please, Sign In to add comment