Last active
August 29, 2015 13:56
-
-
Save gsheppard/9081967 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
#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