Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Original problem from "Seven Languages in Seven Weeks", Day 1
- # Problem statement :: Write a program that picks a random number. Let a player guess the number, telling the player whether the guess is too low or too high
- # this is a good illustration of the do-while looping construct in ruby
- # please note that this is not a documented language feature and hence its ill adviced to use it.
- begin
- puts "Guess a number within 1 to 10"
- guess = gets.chomp.to_i
- if guess>actual
- puts "You have guessed a HIGHER number ... try again"
- elsif guess<actual
- puts "You have guessed a LOWER number ... try again"
- end
- end until actual==guess
- puts "you have guessed the right number !!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement