Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. # NUMBER GUESSING GAME (9/21/17)
  2. #
  3. # #Pseudocoding practice:
  4. # # FIRST: generate a random number (solution) from 1-100
  5. # #
  6. # # INPUT: Ask the user for a guess
  7. # #
  8. # # IF guess == solution THEN print "You guessed the right number"
  9. # # ELSE "guess again" and prompt user for another guess
  10. # # CALL on hint function and give user a hint
  11. # HINT: could be higher or lower
  12. # HINT(option): give a mathematical hint
  13. # # ELSE IF user inputs "c" then print solution
  14.  
  15. #INITIALIZATION
  16.  
  17. puts "I have generated a random number between 1 and 100 for you to guess, what is your guess?"
  18. solution = rand(100) + 1
  19. guess = nil
  20.  
  21.  
  22. # MAIN PROGRAM
  23. while guess.to_i != solution
  24. puts "What is your guess (1-100)?"
  25. guess = gets.chomp
  26. if guess.downcase == "c"
  27. puts "The number is: #{solution}, you cheater!"
  28. guess = solution # this will exit the loop
  29. elsif guess.to_i > solution
  30. puts "Your guess was too high"
  31. elsif guess.to_i < solution
  32. puts "Your guess was too low"
  33. else
  34. puts "you guessed the right number :)"
  35. end
  36. # give bonus hints here
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement