Skip to content

Instantly share code, notes, and snippets.

@Qata
Created March 21, 2018 00:03
Show Gist options
  • Save Qata/90a3bd5a6592cacdb37d9adef0b8914a to your computer and use it in GitHub Desktop.
Save Qata/90a3bd5a6592cacdb37d9adef0b8914a to your computer and use it in GitHub Desktop.
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