
import Control.Monad
import System.Random
import System.IO

main :: IO ()
main = do
  putStrLn "Guess on a number between 1 and 100"
  num <- randomRIO (1,100)
  let guess count = do
        putStr "Your guess: " >> hFlush stdout
        x <- liftM read getLine
        let tryAgain m = putStrLn m >> guess (succ count)
        case compare num x of
          LT -> tryAgain "The number is smaller"
          GT -> tryAgain "The number is bigger"
          EQ -> putStrLn $ unwords
                  ["it took you", show count, "guesses to find the number."]
  guess 1

