任何人都可以帮忙解决这个问题吗?
编写一个程序,询问用户直角三角形的底边和高度,计算其面积并将其打印到屏幕上.交互应该类似于:
The base?
3.3
The height?
5.4
The area of that triangle is 8.91
Run Code Online (Sandbox Code Playgroud)
解决:
getTriArea :: IO Float
getTriArea = do
putStr "The base? "
base <- getLine
putStr "The height? "
height <- getLine
let ar = ( (read base :: Float) * (read height :: Float) )/ 2
return ar
main = do
result <- getTriArea
putStr $ "The area of that triangle is " ++ show result
Run Code Online (Sandbox Code Playgroud)