Skip to content

Instantly share code, notes, and snippets.

@gsheppard
Last active August 29, 2015 13:56
Show Gist options
  • Save gsheppard/9081967 to your computer and use it in GitHub Desktop.
Save gsheppard/9081967 to your computer and use it in GitHub Desktop.
#Guess the Number
#Coded by: Anthony Ross, Greg Sheppard, Dan Clark
MAX = 1000
puts "Guess a number between 0 and #{MAX}: "
guess_num = -1
winning_num = rand(MAX)
while guess_num != winning_num
guess_num = gets.chomp
if guess_num.to_i > MAX || guess_num.to_i < 0 || guess_num.to_i.to_s != guess_num
puts "Invalid input, must enter a number between 0 and #{MAX}."
elsif guess_num.to_i < winning_num
puts "Too low, try again..."
else
puts "Too high, try again..."
end
end
puts "Congratulations, You've guessed the number"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment