From: Martin DeMello Date: 2008-07-27T14:14:50+09:00 Subject: Re: deaf grandma. On Sat, Jul 26, 2008 at 8:31 PM, Houston Barnett-gearhart wrote: > if anyone's able to get me started in the right direction, i'd > appreciate it. there's also an extension to the exercise & it states, > "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." but, i'll worry about that after i've got > the previous stuff squared away. thanks in advance. Here's an iterative approach to solving this: 0. Write an echo program. Ask the user for some input, repeat it back and exit. E.g. $ ruby grandma.rb Please say something: Hello world You said: Hello world 1. Set up an echo loop: ask the user for some input, then say it back, then repeat those two steps endlessly 2. Write an expression that returns 'true' if a string is in all caps and false otherwise 3. Have your program only echo back if the input is in all caps 4. Add the "huh? i can't hear you!" if the input is not in all caps Look up the section titled "Branching" in http://pine.fm/LearnToProgram/?Chapter=06 if you have trouble with steps 3 and 4 5. Now go back to the code that says what to do if grandma *can* hear you, and add your random number code It might be helpful to write your program out as an algorithm first (i.e. forget about syntax, just write out the flow of logic. For example, this is the Mrs Gabbard code from chapter 6 written out as an algorithm: Introduce yourself as Mrs Gabbard Ask the student for his/her name See if the name is properly capitalised ---If it is ------Ask the student to take a seat ---Otherwise ------Work out the properly capitalised form ------Ask if that is what the student meant ------If the answer is 'yes' ---------Say "take a seat" ------If not ---------Say "get out!" martin