All pastes #16950 Raw Edit

guess.hs

public text v1 · immutable
#16950 ·published 2005-07-05 16:16 UTC
rendered paste body
module Main
    where

import IO
import Random

main = do
    hSetBuffering stdin LineBuffering
    num <- randomRIO (1::Int, 100)
    putStrLn "I'm thinking of a number between 1 and 100"
    doGuessing num

doGuessing num = do
    putStrLn "Enter your guess:"
    guess <- getLine
    let guessNum = read guess
    if guessNum < num
        then do putStrLn "Too low!"
            doGuesssing num
        else if read guess > num
            then do putStrLn "Too high!"
                doGuessing num
            else do putStrLn "You win!"