Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # NUMBER GUESSING GAME (9/21/17)
- #
- # #Pseudocoding practice:
- # # FIRST: generate a random number (solution) from 1-100
- # #
- # # INPUT: Ask the user for a guess
- # #
- # # IF guess == solution THEN print "You guessed the right number"
- # # ELSE "guess again" and prompt user for another guess
- # # CALL on hint function and give user a hint
- # HINT: could be higher or lower
- # HINT(option): give a mathematical hint
- # # ELSE IF user inputs "c" then print solution
- #INITIALIZATION
- puts "I have generated a random number between 1 and 100 for you to guess, what is your guess?"
- solution = rand(100) + 1
- guess = nil
- # MAIN PROGRAM
- while guess.to_i != solution
- puts "What is your guess (1-100)?"
- guess = gets.chomp
- if guess.downcase == "c"
- puts "The number is: #{solution}, you cheater!"
- guess = solution # this will exit the loop
- elsif guess.to_i > solution
- puts "Your guess was too high"
- elsif guess.to_i < solution
- puts "Your guess was too low"
- else
- puts "you guessed the right number :)"
- end
- # give bonus hints here
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement