Last active
December 28, 2015 08:49
-
-
Save faizaanshamsi/7474351 to your computer and use it in GitHub Desktop.
Random Number Guessing Game
This file contains hidden or 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
MAX = 30 | |
random_number = rand(MAX+1) #This makes the range of possible number 0 to MAX, inclusive. | |
user_correct = false | |
while user_correct == false do | |
print "Guess number between 0 and #{MAX}: " | |
user_guess = gets.chomp | |
if ((0..MAX).include?(user_guess) == false) || user_guess[/\D/] == true | |
puts "Invalid input, must enter a number between 0 and #{MAX}." | |
end | |
if user_guess == random_number | |
user_correct = true | |
puts "Congratulations, you guessed the number!" | |
elsif user_guess < random_number | |
puts "Too low, try again!" | |
else | |
puts "Too high, try again!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment