Created
July 31, 2012 14:03
-
-
Save Centaur/3217281 to your computer and use it in GitHub Desktop.
haskell guess
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
askAndCompare :: Int -> Int -> IO () | |
askAndCompare target level = do | |
putStr "Input your guess:" | |
hFlush stdout | |
input <- getLine | |
case compare (read input) target of | |
LT -> do putStrLn "Too small! Try again." | |
askAndCompare target (level + 1) | |
GT -> do putStrLn "Too Big! Try again." | |
askAndCompare target (level + 1) | |
EQ -> putStrLn $ "Bingo! You take " ++ (show level) ++ " times!" | |
main = do | |
target <- randomRIO(1, 100) | |
askAndCompare target 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment