So I've been learning Haskell on my own from a site I saw here, but I didn't get so far and I already have an assignment ><
This is one of the questions :
I need to do a real live average calculator (I.e put in a number and then add it to a list, show the average, prompt user to input another one, show the average, etc)
I did this:
Code
main = do
putStrLn "Hello, please enter a number and I will calculate the average: "
putStrLn "1."
input = getLine
a = input:[]
calculateAvrg a
putStrLn "2. "
input = getLine
b = input:[a]
calculateAvrg b
putStrLn "3. "
input = getLine
c = input:[b]
calculateAvrg c
putStrLn "4. "
input = getLine
d = input:[c]
calculateAvrg d
putStrLn "5. "
input = getLine
e = input:[d]
calculateAvrg e
putStrLn "6. "
input = getLine
f = input:[e]
calculateAvrg f
putStrLn "7. "
input = getLine
g = input:[f]
calculateAvrg g
putStrLn "8. "
input = getLine
h = input:[g]
calculateAvrg h
putStrLn "9. "
input = getLine
i = input:[h]
calculateAvrg i
putStrLn "10. "
input = getLine
j = input:[i]
calculateAvrg j
calculateAvrg :: (Fractional a) => [a] -> String
calculateAvrg x
| (length x) <= 10 = putStrLn ("The average is " ++ (sum x)/(length x))
| otherwise = putStrLn("We are done!")
It won't run, the code is probably the most inefficient thing you've ever seen, but I just can't figure this language out.
If anyone is familiar and good with Haskell plz plz let me know I REALLY need help with this assignment...