From: "Michael W. Ryder" <_mwryder@...> Date: 2009-10-21T09:25:06+09:00 Subject: Re: Deaf Grandma Chris Mr. wrote: > danielj wrote: >> Thanks very much for all the help guys. >> >> Programmers seem to be a nice group! > > I rewrote some of it like this: > > #Grandma is deaf! > > puts "Hey Sonny! It's your lovely Grandmother! How are you?" > > response = gets.chomp > bye = 0 > > while bye < 1 > if response != response.upcase > puts "Huh?! I CAN'T HEAR YOU!" > end > > if (response == response.upcase and response != "BYE") > puts "NO! NOT SINCE " + (1930+rand(21)).to_s + "!" > end > > if response == "BYE" > puts "GOOD BYE, SONNY!" > bye = (bye+1) > end > > response = gets.chomp > end > > I'm a noob, but this seems cleaner to me. I know there is a way to write > it with out repeating the "if" statements three times but at least it > works:) The only other thing that bothers me is you have to press enter > at the end to return to the command prompt. If anyone has an example on > how to fix it that would be sweet. How about: #Grandma is deaf! puts "Hey Sonny! It's your lovely Grandmother! How are you?" while (response = gets.chomp) != "BYE" if response != response.upcase puts "Huh?! I CAN'T HEAR YOU!" end if (response == response.upcase) puts "NO! NOT SINCE " + (1930+rand(21)).to_s + "!" end end puts "GOOD BYE, SONNY!" This only uses one entry of response and no flags.