Created
March 21, 2018 00:03
-
-
Save Qata/90a3bd5a6592cacdb37d9adef0b8914a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data TicketCategory = Infant | Child | Adult | |
recurseTickets :: Int -> IO Double | |
recurseTickets 0 = pure 0.0 | |
recurseTickets n = do | |
putStrLn "How old is the passenger?" | |
age <- fmap read getLine :: IO Int | |
let priceMultiplier = | |
case age of | |
x | x `elem` [0..4] -> 0 | |
x | x `elem` [5..15] -> 0.5 | |
otherwise -> 1.0 | |
let price = (fromIntegral age) * priceMultiplier | |
fmap (+ price) $ recurseTickets (n - 1) | |
main :: IO () | |
main = do | |
putStrLn "How many tickets would you like to purchase? (Children under 5 travel free)" | |
tickets <- fmap read getLine :: IO Int | |
fmap show (recurseTickets tickets) >>= putStrLn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment