Created
February 12, 2016 17:58
-
-
Save sousatg/67e7336ed0d12dce24fb to your computer and use it in GitHub Desktop.
The game of HILO coded in haskell
This file contains 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
module Hilo where | |
import System.Random as R | |
jogo :: Int -> Int -> IO Int | |
jogo n x = do | |
putStr "Tentativa? " | |
str <- getLine | |
let y = read str | |
if y == x then | |
return n | |
else if y > x then | |
do | |
putStrLn "Demasiado alto!" | |
jogo (n+1) x | |
else | |
do | |
putStrLn "Demasiado baixo!" | |
jogo (n+1) x | |
main :: IO () | |
main = do | |
numero <- R.randomRIO(1,100) | |
n <- jogo 1 numero | |
putStrLn ("Tentativas " ++ show(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment