B
Bianca George
Obviously, I'm working through Chris Pine's Learn to Program, and I'm
having issues with deaf Grandma. I'm new to programming (hence why I'm
reading Learn to Program), and I've gotten as far as getting the program
to recognize when 'BYE' has been entered 3 times in a row. But, for some
reason, it doesn't enter the last loop correctly and give the proper
response once and then stop. Why is this?? After 2 days, this is driving
me crazy! My code so far is as follows:
speak = ''
bye_count = 0
puts 'Hello, Sonny, how are ya?'
speak = gets.chomp
while bye_count != 3
if speak != speak.upcase
bye_count = 0
puts 'You gotta shout, boy, like THIS.'
speak=gets.chomp
elsif speak == speak.upcase && speak != 'bye'.upcase
bye_count = 0
puts 'No, not since ' + (1930+(rand(21))).to_s + '. What else?'
speak = gets.chomp
elsif speak == 'bye'.upcase && bye_count < 3
bye_count += 1
puts 'Where ya goin\', Sonny? I\'ve got all day. bye_count = ' +
bye_count.to_s + '.'
speak = gets.chomp
elsif speak == 'bye'.upcase && bye_count == 3
puts 'Fine, Sonny, I gotta take my nap anyway. bye_count = ' +
bye_count.to_s + '.'
end
end
I greatly appreciate any help with this!!
Thanks,
chipsbgz
having issues with deaf Grandma. I'm new to programming (hence why I'm
reading Learn to Program), and I've gotten as far as getting the program
to recognize when 'BYE' has been entered 3 times in a row. But, for some
reason, it doesn't enter the last loop correctly and give the proper
response once and then stop. Why is this?? After 2 days, this is driving
me crazy! My code so far is as follows:
speak = ''
bye_count = 0
puts 'Hello, Sonny, how are ya?'
speak = gets.chomp
while bye_count != 3
if speak != speak.upcase
bye_count = 0
puts 'You gotta shout, boy, like THIS.'
speak=gets.chomp
elsif speak == speak.upcase && speak != 'bye'.upcase
bye_count = 0
puts 'No, not since ' + (1930+(rand(21))).to_s + '. What else?'
speak = gets.chomp
elsif speak == 'bye'.upcase && bye_count < 3
bye_count += 1
puts 'Where ya goin\', Sonny? I\'ve got all day. bye_count = ' +
bye_count.to_s + '.'
speak = gets.chomp
elsif speak == 'bye'.upcase && bye_count == 3
puts 'Fine, Sonny, I gotta take my nap anyway. bye_count = ' +
bye_count.to_s + '.'
end
end
I greatly appreciate any help with this!!
Thanks,
chipsbgz