Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Help with Exercise from Pine's Learning to Program (Chapter 7)

Reply
Thread Tools

Help with Exercise from Pine's Learning to Program (Chapter 7)

 
 
woodyee
Guest
Posts: n/a
 
      05-02-2006
Help! I'm stuck! I'm using Chris Pine's book and I'm stuck on the first
exercise at the end of chapter 7 ("Deaf Grandma"). Can someone offer
suggestions? I can get the first part (ask, she yells 'speak up' unless
I ask in caps in that case she'll say 'no...') but I'm lost after that.
Thanks so much!

#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!
#You can't stop talking to grandma until you shout BYE.
#Hint: Don't forget about chomp! 'BYE'with an Enter is not the same as
'BYE' without one!
#Hint 2: Try to think about what parts of your program should happen
over and over again.
#All of those should be in your while loop.

ask = gets.chomp
while ask != ask.upcase
puts 'HUH?! SPEAK UP, SONNY!'
ask = gets.chomp
if ask = ask.upcase
puts 'NO! NOT SINCE 1938'
ask = gets.chomp
end
if puts 'BYE'
ask = gets.chomp
end
end

 
Reply With Quote
 
 
 
 
anne001
Guest
Posts: n/a
 
      05-02-2006
Is this your code?
if ask = ask.upcase

shouldn't it be if ask == ask.upcase

have you seen case so far?
it seems to me I would do in pseudocode
loop
get the ask string
case(not uppercase)
speak up
case(BYE)
break out of loop
case (all other cases)
no not since ...
end cases
endloop

To break out of loop, you can set a variable
say wanttostop=0
while(wanttostop==0)
cases...
case BYE
wanttostop=1
end

or there are ways to break out of a loop, don't know how much the book
has covered.

Does this help?
You can use if same as case, if you have not seen case

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[I'm learning C]: Learning to use ucontext Andrey Popp C Programming 5 01-31-2012 01:05 AM
Learning C and Learning Make/Configure/Building/Linking Hal Vaughan C Programming 7 03-21-2006 05:07 PM
A learning exercise...yet another Sudoku solver with GUI engsolnorm@hotmail.com Python 0 01-19-2006 02:04 AM
e-learning, (collaborative learning environment) collinm Java 1 09-08-2005 09:52 PM
learning JavaScript - Need help with an exercise Sean McCourt Javascript 3 03-14-2005 01:14 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57