Skip to content

Instantly share code, notes, and snippets.

@blurredbits
Created March 13, 2014 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blurredbits/9521157 to your computer and use it in GitHub Desktop.
Save blurredbits/9521157 to your computer and use it in GitHub Desktop.
Guessing Game
puts "Let's play a guessing game. "
puts "I'll pick a number from 1 to 20. You try to guess it."
puts "Please enter a number: "
answer = 1 + rand(19)
number_of_guesses = 0
begin
guess = gets.chomp.to_i
if guess < answer
puts "The number is bigger than #{guess}"
else
puts "The number is smaller than #{guess}"
end
number_of_guesses = number_of_guesses + 1
end until guess == answer
puts "Congratulations! You found the number. It is: #{answer}."
puts "It took you #{number_of_guesses} guesses to get the correct answer."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment