From: Pablo Roboto Date: 2010-10-09T02:59:39+09:00 Subject: Re: Chris Pine Program Challenges unknown wrote: > puts 'Type in as many words as you want' > > puts 'When you are finished, press \'ENTER\' on an empty line' > > puts 'I\'ll give \'em all back to you in alphabetical order!' > > stuff = [] > user_input = gets.chomp > > while user_input != '' > > stuff.push(user_input) > > user_input = gets.chomp > > end > > puts stuff.sort.join(', ') > > Here is my code for the "array program" from chapter 7 and the > challenge is to now adapt the program to have the same output without > using the "sort" method. > > I have no idea where to even start. I think we are supposed to iterate > over the array somehow but have no clue. Anybody got a hint for me? > > 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! Just starting myself and enjoying the book (though I'm about to pull my hair out with the sort exercise in Chapter 7 -- the one that challenges you to perform the sort without using .sort) Here's what I did ... # DEAF GRANDMA byecount = 0 puts 'tell me sthign !' while byecount < 3 sonnysays = gets.chomp if sonnysays == sonnysays.upcase if sonnysays == 'BYE' puts 'do not go' byecount = byecount +1 else puts 'more to say?' end else puts 'speak up; cannot hear.' end end puts 'i will miss you sonny' -- Posted via http://www.ruby-forum.com/.