HASKELL   16

hilo

Guest on 22nd September 2022 12:23:47 AM

  1. module Main
  2.         where
  3. -- import two libraries
  4. import IO
  5. import Random
  6.  
  7. main = do
  8.         hSetBuffering stdin LineBuffering
  9.         num <- randomRIO (1::Int, 100) -- generate a short Int between 1 and 100
  10.         putStrLn "I’m thinking of a number between 1 and 100" 100"
  11.         doGuessing num
  12.  
  13. doGuessing num = do
  14.         putStrLn "Enter your guess:"
  15.         guess <- getLine
  16.         let guessNum = read guess
  17.         if guessNum < num
  18.                 then do putStrLn "Too low!"
  19.                         doGuessing num
  20.                 else if read guess > num
  21.                         then do putStrLn "Too high!"
  22.                                 doGuessing num
  23.                 else do putStrLn "You

Raw Paste


Login or Register to edit or fork this paste. It's free.