HASKELL   22

hilo3

Guest on 22nd September 2022 12:25:11 AM

  1. module Main
  2.         where
  3.  
  4. import IO
  5. import Random
  6.  
  7. main = do
  8.         hSetBuffering stdin LineBuffering
  9.         num <- randomRIO (1::Int, 100)
  10.         putStrLn "I’m thinking of a number between 1 and 100" 100"
  11.         doGuessing n-- second argument keeps track of number of guesses
  12. sses
  13. doGuessing num guesses = do
  14.         putStrLn "Enter your guess:"
  15.         guess <- getLine
  16.         if (read guess) < num
  17.                 then do putStrLn "Too low!"
  18.                         doGuessing num (guesses + 1)
  19.                 else if read guess > num
  20.                         then do putStrLn "Too high!"
  21.                                 doGuessing num  (guesses + 1)
  22.                 else do putStrLn ("You Win! Number of guesses:" ++ show(gues

Raw Paste


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