Echo_
2012-04-30 12:05:15
Since I'm bored as hell, here's a little game to play. Write a program that takes a weight and a planet and converts the weight according to how much it would be on that planet.
I wrote mine in Haskell. People should write in in different languages so that we can compare them.
I wrote mine in Haskell. People should write in in different languages so that we can compare them.
module Main where
import qualified Char (toUpper)
toUpperCase :: String -> String
toUpperCase str = [Char.toUpper ch | ch <- str]
planets :: String -> Float
planets str
| planet == "MERCURY" = 0.4155
| planet == "VENUS" = 0.8975
| planet == "EARTH" = 1.0
| planet == "MARS" = 0.3507
| planet == "JUPITER" = 2.5374
| planet == "SATURN" = 1.0677
| planet == "URANUS" = 0.8947
| planet == "NEPTUNE" = 1.1794
| planet == "PLUTO" = 0.0899
| otherwise = 0.0
where planet = toUpperCase str
main :: IO ()
main = do putStrLn "Enter your weight:"
w <- getLine
let weight = read w :: Float
putStrLn "Enter a planet:"
planet <- getLine
let factor = planets planet
if factor == 0.0
then putStrLn "Unknown planet entered"
else putStrLn ("Your weight on " ++ planet ++ " is " ++ show (factor * weight))