Keyboard input/Obtain a Y or N response: Difference between revisions
Keyboard input/Obtain a Y or N response (view source)
Revision as of 02:05, 19 February 2013
, 11 years ago→{{header|Haskell}}: Add Haskell solution
(→{{header|Haskell}}: Add Haskell solution) |
|||
Line 318:
40 IF k$ <> "y" AND k$ <> "Y" AND k$ <> "n" AND k$ <> "N" THEN GOTO 30
50 PRINT "The response was "; k$</lang>
=={{header|Haskell}}==
This may not be very idiomatic:
<lang haskell>import System.IO
hFlushInput :: Handle -> IO ()
hFlushInput hdl = do
r <- hReady hdl
if r then do
c <- hGetChar hdl
hFlushInput hdl
else
return ()
yorn :: IO Char
yorn = do
c <- getChar
if c == 'Y' || c == 'N' then return c
else if c == 'y' then return 'Y'
else if c == 'n' then return 'N'
else yorn
main :: IO ()
main = do
hSetBuffering stdout NoBuffering
putStr "Press Y or N to continue: "
hSetBuffering stdin NoBuffering
hSetEcho stdin False
hFlushInput stdin
answer <- yorn
putStrLn [answer]</lang>
=={{header|Icon}} and {{header|Unicon}}==
|