def dice sides times = let once _ = randInt 1 (sides + 1) in let aux acc times = if times ?= 0 then acc else aux (acc + once ()) (times - 1) in aux 0 times def guessing_game _ = let secret = randInt 1 101 and guessOnce _ = do print "Make your guess: "; let guess = readInt () in if secret > guess then do printLn "My number is larger than that..."; false end else if secret < guess then do printLn "My number is smaller than that..."; false end else true end and shouldEnd times = if guessOnce () then do printLn "Congratulations! You guessed right!"; true end else if times ?= 1 then do printLn "That was your last guess..."; true end else do printLn "Guess again..."; false end and aux times = do print "You have "; print times; printLn " guesses left"; if shouldEnd times then do print "My number was "; printLn secret end else aux (times - 1) end in do printLn "Welcome to the number guessing game"; printLn "I will pick a random number between 1 and 100 (inclusive)"; printLn " and you try to guess it."; printLn "After each guess, I will tell you if my number was larger or smaller"; printLn "Good Luck and Have Fun!"; aux 10 end