Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

java

Name: Anonymous 2007-04-02 21:47 ID:lENHJj++

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: Anonymous 2007-04-03 6:47 ID:jWCrT+sL

import Control.Monad
import Control.Monad.State
import System.Environment

data Shit = Shit Float 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 c 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' c (n + 1) (num:xs)

     getShit)

main :: IO ()
main = do
    putStr "Enter a number: "
    n <- liftM read getLine
    evalStateT getShit (Shit n n n 1 [n])


The worst Haskell code possible > the best Java code possible.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List