Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- #Created by justin beitz
- play = true
- while play == true
- puts "Enter the high number"
- high = gets.to_i
- number = 1+rand(high)
- puts "Enter the maximum number of guesses"
- guesses = gets.to_i
- puts "Enter a number between 1 and " + high.to_s + "."
- guess = gets
- guess = guess.to_i
- count = 1
- while guess != number && count != guesses
- if guess > number
- puts " "
- puts "Too High. Try again:"
- guess = gets.to_i
- count = count + 1
- #if count == guesses
- # puts " "
- # puts "You suck. The answer was " + number.to_s + "."
- # break
- #end
- elsif guess < number
- puts " "
- puts "Too Low. Try again:"
- guess = gets.to_i
- count = count + 1
- #if count == guesses
- # puts " "
- # puts "You suck. The answer was " + number.to_s + "."
- # break
- #end
- else
- break
- end
- end
- if guess == number
- puts " "
- puts "We have a winner!!"
- print "Would you like to play again? (y/n)"
- answer=gets.chomp!
- if answer == 'n'
- play = false
- break
- end
- if
- answer == 'y'
- play = true
- end
- end
- if count == guesses
- puts "It took you " + count.to_s + " guesses."
- print "Would you like to play again? (y/n)"
- answer=gets.chomp!
- if answer == 'n'
- play = false
- break
- else
- answer == 'y'
- play = true
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement