I'm getting the error "No instance for (Fractional Int) arising from a use of ‘/’", from inside a local definition in a function I'm trying to make which determines how many of the (three) given integers are above the average of all of the given integers. So I've created a local definition inside the function to calculate the average so I can then use it for guard checks. I've used the same code in a separate definition (in another file) to calculate the average and it works. I've tried putting the "fromIntegral" function call in different places but it's not working, where am I going wrong?
Here's the code:
howManyAboveAverage :: Int -> Int -> Int -> Int
howManyAboveAverage a b c
| a > average && b > average = 2
| a > average && c > average = 2
| b > average && c > average = 2
| a > average = 1
| b > average = 1
| c > average = 1
| otherwise = 0
where
average = fromIntegral (a + b + c) / 3
The error is being flagged up on the last line.
Thanks.