Skip to content

Instantly share code, notes, and snippets.

@townie
Created February 19, 2014 00:16
Show Gist options
  • Save townie/9083481 to your computer and use it in GitHub Desktop.
Save townie/9083481 to your computer and use it in GitHub Desktop.
def getguess max_num
puts "Guess a number between 0 and #{max_num}: "
guess = gets.chomp
if !( /^[0-9]*/.match(guess) )
puts "Try again! NEED A NUMBER"
getguess (max_num)
end
return guess.to_i
end
max_num = 10
guess = getguess (max_num)
act_num = rand(max_num)
until act_num == guess
guess = getguess (max_num)
if act_num == guess
puts "Congratulations, you've guessed the number"
break
end
puts "Too high, try again... " if act_num <= guess
puts "Too low, try again..." if act_num >= guess
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment