birthday program

July 28, 2009

puts 'Hello, what year were you born in?'
year = gets.chomp
puts 'And month?'
month = gets.chomp
puts 'And day?'
day = gets.chomp

birthday = Time.mktime(year, month, day)

puts 'you were born on ' + birthday.to_s + '.'

#print a "spank" for each year the responder was born.

#First, need to figure out how many years they were born.

#Then, print out the "spank"s.

This program isn’t complete, but I thought I’d post it anyway. Will try to finish later tonight.


if and while loops

July 23, 2009

command = ''
name = gets.chomp
if name == 'chris'
  while command != 'bye'
  puts 'Hello there!'
  command = gets.chomp
  end
else
  while command != 'hello'
    puts 'What?'
    command = gets.chomp
  end
end

I was having a hard time figuring out what embedded while loops did under if end statements. The above program illustrates that if the gets equals the string chris, then the bye while loop will start. If it’s something else, then the hello while loop will start. I was confused by initially reading the code as “if name equals chris, while…”. When coding these types of statements, read them this way: “if x equals chris statement is true, run this while statement”. Keep the two as separate modules.


working with until

July 21, 2009

puts 'Hello, What\'s your name?'
name = gets.chomp
until name == 'Chris'
  puts 'Hello, ' + name + '.'
  puts 'I\'m looking for someone special. The man named Chris. ' \
     'What\'s your name again?'
  name = gets.chomp
  if name == 'Chris'
    puts 'You are the one.'
  end
end
puts 'Please help us, ' + name + '. Can you help us solve this problem? '
response = gets.chomp
if response =='yes'
  puts 'What\'s the meaning of Hello World?'
  response2 = gets.chomp
  if response2 == 'The beginning of programming.'
    puts 'Thanks!'
  else
    puts 'that doesn\'t help us.'
  end
end

My half-baked deaf grandma program

July 17, 2009

#A Deaf Grandma Program
puts 'Hello boy, how are ye?' #Introduction sentence. Grandma says hi.
response = gets.chomp #My response to the grandma.
while response != 'BYE'
puts 'No, not since ' + (rand(20) + 1930).to_s + '.' #She's deaf, remember?
response = gets.chomp
end
puts 'Alright sonny, see you later.' #aww, how sweet.