danielj / sleepingindian.org wrote:

 > Secondly, I have a question about this code for my Deaf Grandmother
 > program:
 >
 > gcount = 0
 >
 > puts "Hello child! How are yeah?"
 >
 > while gcount < 3
 >
 >  r = gets.chomp
 >
 >   if r == r.downcase or r == r.capitalize
 >    puts 'WHAT? YOU\'RE GONNA HAVE TO SPEAK UP!'
 >   end
 >
 >   if (r == r.upcase and r != 'BYE')
 >    puts 'NOT SINCE 19' + (rand(21)+30).to_s + '!'
 >   end
 >
 >   if r == 'BYE'
 >    puts 'NOT SINCE 19' + (rand(21)+30).to_s + '!'
 >    gcount = gcount + 1
 >   end
 >
 >   if r != 'BYE'
 >    gcount = 0
 >   end
 >
 >  end
 >
 > The only problem with my program is when a user inputs something of
 > mixed case the program doesn't respond with "WHAT? YOU'RE GONNA HAVE
 > TO SPEAK UP!" like it should...
 >
 > Any ideas?
 >
 > Thanks a lot!
 >

Hi Daniel,

I'm also working through this book and having a lot of fun with it. 
This is what I ended up with on the Granma prog (I added to the middle 
part so she'd say a final farewell message, although obviously that 
could be reduced to just "if speech == 'BYE' bye_num = bye_num + 1 
else... etc" to make the prog shorter):

bye_num = 0

while bye_num != 3
     puts 'What do you have to say to Granma?'
     speech = gets.chomp
     if speech == 'BYE'
         if bye_num == 2
             puts 'OKAY, LEAVE ME THEN.'
             bye_num = bye_num + 1
         else
             puts 'WHAT\'S THAT DEAR?'
             bye_num = bye_num + 1
         end
     else
         bye_num = 0
         if speech == speech.upcase
             puts 'NO, NOT SINCE 19' + (rand(21) + 30).to_s  + '!'
         else
             puts 'HUH?!  SPEAK UP, SONNY!'
         end
     end
end


Take care,
Matt