John Kriple wrote: > I'm trying to figure out how to get a user to be able to submit guesses > in a guessing game multiple times. > > This is what I have so far: > > print "I am thinking of a number between 1 and 10 , can you guess what > it > is? " > > num = gets > num = num.chomp > num = num.to_i > > > if num == 4 > puts "You got it!" > elsif num < 4 then > puts "Guess Again" > elsif num > 5 then > puts "Guess Again" > > > How do I make it so they can keep guessing until they get it right? > > Thanks There seem to be a slight bug in the if clause, what happens if the number is 5? There are many ways to do ask for multiple guesses, here is one way to do it without a loop construct, with the if clause corrected. catch :right_guess do num = gets num = num.chomp num = num.to_i if num == 4 puts "You got it!" throw :right_guess elsif num < 4 then puts "Guess Again" redo elsif num > 4 then puts "Guess Again" redo end end -- Kind Regards, Rajinder Yadav http://DevMentor.org Do Good ~ Share Freely