loading...

re: Daily Challenge #241 - Tip Calculator VIEW POST

FULL DISCUSSION
 

Haskell

module Main (main) where

maybeTip :: Float -> String -> Maybe Int
maybeTip price "poor"       = Just $ ceiling $ price * 0.05
maybeTip price "good"       = Just $ ceiling $ price * 0.1
maybeTip price "great"      = Just $ ceiling $ price * 0.15
maybeTip price "excellent"  = Just $ ceiling $ price * 0.2
maybeTip _ _                = Nothing

main :: IO ()
main = do
    print $ maybeTip 30 "poor"          -- Just 2
    print $ maybeTip 20 "hi"            -- Nothing
    print $ maybeTip 107.65 "great"     -- Just 17
    print $ maybeTip 78 "good"          -- Just 8
    print $ maybeTip 50 "poor"          -- Just 3
    print $ maybeTip 125 "excellent"    -- Just 25
code of conduct - report abuse