Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created March 24, 2016 03:42
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 anonymous/bb1cce633d9f58973c9f to your computer and use it in GitHub Desktop.
Save anonymous/bb1cce633d9f58973c9f to your computer and use it in GitHub Desktop.
def start_game
# Generate
remaining_guesses = 10
guess = nil
print ("Let's play a guessing game! Enter a max number: ")
max_number = gets.to_i
number_to_guess = 1 + (max_number)
puts ('I am thinking of a number between 1 and ' + (max_number.to_s))
# Guess
while remaining_guesses > 0 && guess != number_to_guess
print ('Guess a number: ')
guess = gets.to_i
if guess == max_number
print ('You win!')
elsif guess != max_number
print ('You lose!')
remaining_guesses = remaining_guesses - 1
#print remaining_guesses test
else
print ('Error: Please enter a valid number')
end
end
end
start_game()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment