fork download
  1. import System.IO
  2.  
  3. prompt :: String -> IO String
  4. prompt text = do
  5. putStr text
  6. hFlush stdout
  7.  
  8. sqrtEquation :: Double -> Double -> Double -> String
  9. sqrtEquation a b c
  10. | d < 0 = "No solutions"
  11. | d == 0 = (show x1)
  12. | d > 0 = (show x1) ++ " and " ++ (show x2)
  13. where d = (b*b - 4*a*c)
  14. x1 = ((-b + sqrt(d))/2*a)
  15. x2 = ((-b - sqrt(d))/2*a)
  16.  
  17.  
  18. main = do
  19. a <- prompt "Input a: "
  20. b <- prompt "Input b: "
  21. c <- prompt "Input c: "
  22. let result = sqrtEquation (read a) (read b) $ read c
  23. putStrLn result
  24.  
Success #stdin #stdout 0s 4824KB
stdin
1
1
-6
stdout
Input a: Input b: Input c: 2.0 and -3.0