Advertisement
vencinachev

PrintDigit

Nov 18th, 2020
1,350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. main :: IO()
  2. main = do
  3.     printInfo
  4.  
  5. printInfo :: IO()
  6. printInfo = do
  7.     input <- getLine
  8.     if input /= "End" then
  9.         do
  10.             let info = printDigit input
  11.             putStrLn (show info)
  12.             printInfo
  13.     else
  14.         putStr ""
  15.  
  16. printDigit :: String -> String
  17. printDigit "0" = "Zero"
  18. printDigit "1" = "One"
  19. printDigit "2" = "Two"
  20. printDigit "3" = "Three"
  21. printDigit "4" = "Four"
  22. printDigit "5" = "Five"
  23. printDigit "6" = "Six"
  24. printDigit "7" = "Seven"
  25. printDigit "8" = "Eight"
  26. printDigit "9" = "Nine"
  27. printDigit _   = "Please only enter single digit positive numbers"
  28.  
  29. printDigit2 :: String -> String
  30. printDigit2 n = case n of
  31.             "0" -> "Zero"
  32.             "1" -> "One"
  33.             "2" -> "Two"
  34.             "3" -> "Three"
  35.             "4" -> "Four"
  36.             "5" -> "Five"
  37.             "6" -> "Six"
  38.             "7" -> "Seven"
  39.             "8" -> "Eight"
  40.             "9" -> "Nine"
  41.             _ -> "Please only enter single digit positive numbers"
  42.  
  43. printDigit3 :: Int -> String
  44. printDigit3 n
  45.     | n >= 0 && n <= 9 = list !! n
  46.     | otherwise = "Please only enter single digit positive numbers"
  47.     where
  48.         list = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement