我是 Erlang 初学者,正在尝试制作一个简单的命令行应用程序,用户可以在其中输入地板的宽度和高度、每平方英尺地板的成本,然后返回价格。本质上,我只是接受三个整数值并返回产品。
23> c(costcalc).
{ok,costcalc}
24> costcalc:start().
Calculate the cost of flooring based on width, height, and cost per square foot.
Width in feet: 5
Height in feet: 5
Cost in dollars per square foot: $4
** exception error: an error occurred when evaluating an arithmetic expression in function costcalc:start/0 (costcalc.erl, line 23)
这是我正在使用的代码:
start() ->
io:format("Calculate the cost of flooring based on width, height, and cost per square foot.\n"),
W = string:to_integer(io:get_line("Width in feet: ")),
H = string:to_integer(io:get_line("Height in feet: ")),
C = string:to_integer(io:get_line("Cost in dollars per square foot: $")),
Cost = W * H * C,
io:fwrite(Cost).
第 23 行Cost = W * H * C,
应该是 100。当我5 * 5 * 4.
直接在 shell 中运行时,它可以毫无问题地计算。我还应该注意,无论我是否使用我想我可以不用的 string:to_integer() 都会发生这种情况。
我错过了什么?