diff --git a/cout-recette.hs b/cout-recette.hs new file mode 100755 index 0000000..9895ef5 --- /dev/null +++ b/cout-recette.hs @@ -0,0 +1,34 @@ +#! /usr/bin/env runhaskell + +type Ingredient = (String, Double, Double) + +type Recette = ( String, [Ingredient], Double, Double) + +ingredientsLessive :: [Ingredient] +ingredientsLessive = ( "Lessive" + , [ ("Eau", 0.003, 2.5) + , ("Savon de Marseille", 3.36, 0.1) + , ("Bicarbonate de soude", 3.81, 0.016) + , ("Vinaigre blanc", 0.36, 0.03) + ] + , 2.5 + , 30 + ) + +quantiteLessive = 2.5 +nombreUtilisations = 30 + +prixTotal ingredientsLessive = sum . map (\ (_, x, y) -> x * y) $ ingredientsLessive + +prixLitre prixTotal quantiteLessive = prixTotal / quantiteLessive + +prixUtilisation prixTotal quantiteLessive = prixTotal / nombreUtilisations + +main = do + putStrLn "Calcul du coût des recettes\n" + putStrLn "* Lessive :" + print ingredientsLessive + putStrLn $ " * Prix Total = " ++ show prixTotal ++ "€" + putStrLn $ " * Prix au litre = " ++ show prixLitre ++ "€" + putStrLn $ " * Prix par utilisation = " ++ show prixUtilisation ++ "€" +