On Tue, Nov 9, 2010 at 11:31 PM, Steve Rees <stevoreesimo / hotmail.com> wrote:
> I am new to programming and have been learning Ruby using online
> tutorials to write simple programs that I understand.
>
> I have written a short code for a program which asks you to guess a
> number and tells you that you are/ are not psychic if you guess it
> correctly.
> I want to put in a function that allows you to continue playing if you
> wish or leave when you want to.
>
> Below is the code I have come up with so far, I am aware it is ugly and
> could be far more concise but it is laid out in a way that I can
> understand the flow. If you too have read the same tutorials you will
> see that I have cut, pasted and ammended from these. Please can anyone
> tell me what I need to add to loop the game as I have described above?

To put it abstractly: you need to change the looping condition.
Currently you loop until the user guesses the number correctly.  Now
there are two ways to look at the proposed change:

1. You want to loop until the user explicitly states that he wants to
quite (e.g. by entering "quit").
2. You want to loop as long as the user explicitly states that he
wants another round ("Do you want more? [y/n]")

It seems option 1 is a smaller change (i.e. you only need to change
how "goodAnswer" is set).  Btw, conventionally the variable should be
named "good_answer").

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/