Hi i’m trying to write and example program where you speak to a
grandmother who cannot hear well. you need to write everything in
capital letters or she wont hear you. When you Say BYE the program is
finished.
My problem is that when i say BYE it first answers me and after that
finishes the program. I would like that after i write BYE it should
finish the program immediately and not answer me before that.
Test for BYE before answering.
Sorry Im not sure what you mean. The program has two Rules, if your
writing is in downcase It replies you that she cannot hear. If its in
upcase it replies you differently. What i would want to happen when i
write BYE is to Tell the program to stop the loop and the program would
finish. But It first reads That BYE is in upcase, replies me and then
finishes the program and i havent found a way to do this.
pseudocode
if text == “BYE”
exit
elsif text != text.uppercase
say “she cant hear you”
else
anwser
end
You have something that tests for “BYE” and exits right? And you have
something that responds to uppercase right? Move the bit that tests for
“BYE” and exits above the bit that responds to uppercase text.
OK, so now do what we said. Move the logic for the BYE test to before
the
output for granny’s text.
Think about how you could do that. Here are some questions to help you:
Where is the logic for testing for BYE now?
What could you do to move it?
How can you loop forever?
How do you exit from a loop from inside the loop?
Thanks i I got It now and learned a bit more about looping.
Thank you everyone.
homework. seen this before.
Sorry i uploaded the wrong file. Heres the right one.
On Tue, Jul 19, 2011 at 6:47 PM, Stu [email protected] wrote:
homework. seen this before.
That’s because it’s one of the first exercises for Chris P.'s Learn
To Program. That’s not usually used as a textbook for comp.sci.
programming courses.
So, instead of being completely dismissive, help a poor guy/gal out,
and put him/her onto the right track, eh?
–
Phillip G.
phgaw.posterous.com | twitter.com/phgaw | gplus.to/phgaw
A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
– Leibniz
Ok now I understand where it came from. Just triggered the reaction as
the same exact problem came up before.
My humble apologies to the OP. Enjoy learning ruby.
~Stu
On Tue, Jul 19, 2011 at 11:51 AM, Phillip G.