From: Scott Gonyea Date: 2010-11-10T08:28:47+09:00 Subject: Re: help with code, new to programming Ooh, I love these kinds of questions :D Here's my entry: print 'I am going to test if you are psychic, press enter to continue...' gets begin print "I am thinking of a number between 1 and 10, can you guess what it is?\n : " guess = gets.to_i puts "As to the question of you being psychic, the answer is: #{guess}" print 'Play again? [Y/n]: ' end while (again = gets) !~ /^n/i Scott On Nov 9, 2010, at 2:58 PM, Vicente Bosch Campos wrote: > > Hi Steve, > > The main loop of the game would be as follows: > > print 'I am going to test if you are psychic, press enter to > continue...' > initialise = gets > reply='yes' > > while reply=='yes' > matches = ask 'I am thinking of a number between 1 and 10, can you guess what it is?' > puts 'As to the question of you being psychic the answer is:' > puts matches > puts 'Would you like to play again? (please answer yes or no' > reply = gets.chomp > end > > puts 'Goodbye and farewell...' > > Probably there is a more idiomatic way of doing it and also you should check better for the inputed value from the user ( something to investigate for you in the future). > > Regards, > V. > > > On Nov 9, 2010, at 11:31 PM, Steve Rees wrote: > >> print 'I am going to test if you are psychic, press enter to >> continue...' >> initialise = gets >> matches = ask 'I am thinking of a number between 1 and 10, can you guess >> what it is?' >> puts 'As to the question of you being psychic the answer is:' >> puts matches >> puts 'Would you like to play again? (please answer yes or no' >> reply = gets.chomp >> if reply == 'yes' >> matches = ask 'I am thinking of a number between 1 and 10, can you guess >> what it is?' >> else >> puts 'Goodbye and farewell...' >> end > >