Skip to content

Instantly share code, notes, and snippets.

@MelanieS
Created October 29, 2010 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MelanieS/652808 to your computer and use it in GitHub Desktop.
Save MelanieS/652808 to your computer and use it in GitHub Desktop.
# Try to figure out if there is a way to chomp & convert to an integer on
# same line (lines 7 and 8)
# Try to figure out how to print failure message (lines 14-16 & 20-22) for
# both cases in which the user is incorrect without having it in the program
# twice.
randNumber = rand(10)
randNumber = randNumber + 1
print( 'Guess my number! Enter a number (1-10): ')
userNumber = gets.chomp.to_i()
if userNumber == randNumber
puts( 'You guessed correctly! You are SOOO smart!')
elsif userNumber > randNumber
puts( "Your number (#{userNumber}) is higher than my number (#{randNumber}.")
print( "You are unable to guess again because you are such a failure. It
has nothing to do with my inability to program this such that you could
guess again.")
else
puts( "Your number (#{userNumber}) is lower than my number (#{randNumber}.)")
print( "You are unable to guess again because you are such a failure. It
has nothing to do with my inability to program this such that you could
guess again.")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment