Created
December 17, 2011 12:37
-
-
Save omegatakuma/1490116 to your computer and use it in GitHub Desktop.
家族4人の年齢を入力して平均を出すだけのプログラム
This file contains 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
sumTo x = (read :: String -> Int) x | |
getInt = do m <- getLine ; return (sumTo m) | |
family list = (sum list) `div` (length list) | |
main = do | |
putStrLn "mother " ; m <- getInt | |
putStrLn "father " ; f <- getInt | |
putStrLn "brother " ; b <- getInt | |
putStrLn "me " ; me <- getInt | |
putStr ("平均年齢は" ++ (show (family [m, f, b, me])) ++ "歳。") | |
{- /演算子を使うとDouble型に変換しなければ行けないので`div`を使いました。 | |
それとgetLineだとIntで出力されないんでread関数を使ってgetInt関数を作りました。便利です。-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment