0
votes

Expected input:
4
20.0000
5.0000
0.5000
-0.5000
Expected OUTPUT:
20.0000
5.0000
0.5000
-0.5000
The following is my code but its throwing the error:
Crash dump is being written to: erl_crash.dump...done init terminating in do_boot ()

kilo(0)->
    ok;
kilo(N) when N>0->
    {ok,[M]}=io:fread("", "~f"),
    io:format("~f~n",[M]),
    kilo(N-1).
main()->
    {ok,[M]}=io:fread("","~d"),
    kilo(M).
1
That code works for me. How do you start it? Do you get any other error message?legoscia

1 Answers

1
votes

io:fread("", "~f") fails with error when the input is not a float. you can change it like this:

kilo(N) when N>0->
    case io:fread("", "~f") of
        {ok,[M]} -> io:format("~f~n",[M]);
        _ -> ok
    end,
    kilo(N-1).