# Strange Bug - Hard to Title

**URL:** <https://www.ruby-forum.com/t/strange-bug-hard-to-title/89090>\
**Category:** Ruby-Forum\
**Created:** [March 17, 2007, 5:00am UTC](https://www.ruby-forum.com/t/strange-bug-hard-to-title/89090 "2007-03-17T05:00:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [March 17, 2007, 5:00am UTC](https://www.ruby-forum.com/t/strange-bug-hard-to-title/89090/1 "2007-03-17T05:00:25Z")

</div>

Yeah, I know. Very bad topic title, but there is no quick way to  
describe this problem in 2 words:

I am learning Ruby right now, and I am using the wonderful Learning R.  
guide by Satish T… I am currently at the chapter “Random Numbers”  
and I am trying to do the following:

This assignment is from Chris P.'s Book.

1. Write a Deaf Grandma program. Whatever you say to grandma  
(whatever you type in), she should respond with HUH?! SPEAK UP, SONNY!,  
unless you shout it (type in all capitals). If you shout, she can hear  
you (or at least she thinks so) and yells back, NO, NOT SINCE 1938! To  
make your program really believable, have grandma shout a different year  
each time; maybe any year at random between 1930 and 1950. You can’t  
stop talking to grandma until you shout BYE.
2. Extend your Deaf Grandma program: What if grandma doesn’t want you  
to leave? When you shout BYE, she could pretend not to hear you. Change  
your previous program so that you have to shout BYE three times in a  
row. Make sure to test your program: if you shout BYE three times, but  
not in a row, you should still be talking to grandma.

I have done all of that, but I have one problem. I am using SciTE, and  
am using the F5 thing to try out my code. My one problem is that when I  
run the program, the correct text comes on, but I have to press enter  
twice for the while loop to start. Sounds confusing, I know, so here is  
my code:

bye\_response = 0  
years = (1930…1950).to\_a

puts “'Ey sonny! Long time no chat with your old nonna, eh? How ya  
been!?”  
STDOUT.flush

response = gets.chomp  
while bye\_response != 3  
response = gets.chomp  
if bye\_response == 2  
puts “FINE! LEAVE YOUR OLD NONNA!”  
bye\_response += 1  
elsif response == “BYE”  
puts “HUH!? WHAT WAS THAT!?”  
bye\_response += 1  
elsif response == response.upcase  
puts "NO, NOT SINCE " + years[rand(years.max - years.min)].to\_s +  
“!”  
bye\_response = 0  
else  
puts “HUH?! SPEAK UP, SONNY!”  
bye\_response = 0  
end  
STDOUT.flush  
end

Try it out in SciTE and you’ll see what I mean. Thanks a lot!

---

<div class="post-metadata">

**Author:** ![michaelb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaelb](https://www.ruby-forum.com/u/michaelb)\
**Post date:** [March 17, 2007, 5:06am UTC](https://www.ruby-forum.com/t/strange-bug-hard-to-title/89090/2 "2007-03-17T05:06:26Z")

</div>

Firstly - I am very, very sorry, this is the complete wrong category. My  
bad 😊

Secondly - I have updated the code a bit:

bye\_response = 0  
years = (1930…1950).to\_a

puts “'Ey sonny! Long time no chat with your old nonna, eh? How ya  
been!?”  
STDOUT.flush

response = gets.chomp  
while bye\_response != 3  
response = gets.chomp  
if response == “BYE”  
if bye\_response == 2  
puts “FINE! LEAVE YOUR OLD NONNA!”  
else  
puts “HUH!? WHAT WAS THAT!?”  
end  
bye\_response += 1  
elsif response == response.upcase  
puts "NO, NOT SINCE " + years[rand(years.max - years.min)].to\_s +  
“!”  
bye\_response = 0  
else  
puts “HUH?! SPEAK UP, SONNY!”  
bye\_response = 0  
end  
STDOUT.flush  
end

Once again, thanks a ton 🙂
