Created
February 19, 2014 00:16
-
-
Save townie/9083481 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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