i have to create a loop, in the loop i have to take the input values (from keyboard) and then output min/max and average of the values entered. I have no problem with the average, but the only way i can find how to figure the min/max is through a text file example, which doesnt help me when it has to be through keyboard. help pls
8)
Name:
Anonymous2007-04-03 6:52 ID:jWCrT+sL
oops. Don't really need to keep track of the average
import Control.Monad.State
data Shit = Shit Float Float Int [Float]
deriving Show
getShit :: StateT Shit IO ()
getShit = do
lift $ putStr "Enter a number: "
str <- lift getLine
when (str /= "q") (do
(Shit a b n xs) <- get
let num = read str
let min' = if num < a then num else a
let max' = if num > b then num else b
let avg' = (foldr1 (+) (num:xs)) / fromIntegral n
lift $ putStrLn $ "minimum is " ++ show min'
lift $ putStrLn $ "maximum is " ++ show max'
lift $ putStrLn $ "average is " ++ show avg'
put $ Shit min' max' (n + 1) (num:xs)
getShit)
main :: IO ()
main = do
putStr "Enter a number: "
n <- liftM read getLine
evalStateT getShit (Shit n n 1 [n])