Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. #Created by justin beitz
  3.  
  4.  
  5. play = true
  6.  
  7. while play == true
  8.  
  9. puts "Enter the high number"
  10. high = gets.to_i
  11. number = 1+rand(high)
  12.  
  13. puts "Enter the maximum number of guesses"
  14. guesses = gets.to_i
  15.  
  16. puts "Enter a number between 1 and " + high.to_s + "."
  17. guess = gets
  18. guess = guess.to_i
  19. count = 1
  20.  
  21. while guess != number && count != guesses
  22. if guess > number
  23. puts " "
  24. puts "Too High. Try again:"
  25. guess = gets.to_i
  26. count = count + 1
  27. #if count == guesses
  28. # puts " "
  29. # puts "You suck. The answer was " + number.to_s + "."
  30. # break
  31. #end
  32.  
  33. elsif guess < number
  34. puts " "
  35. puts "Too Low. Try again:"
  36. guess = gets.to_i
  37. count = count + 1
  38. #if count == guesses
  39. # puts " "
  40. # puts "You suck. The answer was " + number.to_s + "."
  41. # break
  42. #end
  43. else
  44. break
  45. end
  46. end
  47.  
  48. if guess == number
  49. puts " "
  50. puts "We have a winner!!"
  51. print "Would you like to play again? (y/n)"
  52. answer=gets.chomp!
  53. if answer == 'n'
  54. play = false
  55. break
  56. end
  57.  
  58. if
  59. answer == 'y'
  60. play = true
  61. end
  62. end
  63.  
  64. if count == guesses
  65. puts "It took you " + count.to_s + " guesses."
  66. print "Would you like to play again? (y/n)"
  67. answer=gets.chomp!
  68. if answer == 'n'
  69. play = false
  70. break
  71.  
  72.  
  73. else
  74. answer == 'y'
  75. play = true
  76. end
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement