[erlang-questions] Newbie Question about io:format

Hakim Fajardo keam7095@REDACTED
Tue Feb 21 10:15:56 CET 2017


First, thank you because this is a great resource.

Second, I started writing basic programs every day to improve my Erlang
coding. I wrote a simple program that calculates the average of a list of
numbers. But I keep getting this error about io:format.


prices([]) ->
    [],
    io:format("List is empty ~n");

%% determine number of items in the list to calculate average%%

prices(L) when is_list(L) ->
  Size = length(L),
  Sum1 = lists:sum(L),
  Av1 = Sum1 / Size,
  io:format("The average equals ~n", Av1).


Then..

Eshell V8.2  (abort with ^G)
1> L = [1,2,2,2,3,3,4].
[1,2,2,2,3,3,4]

2> c(standev).
{ok,standev}

3> standev:prices(L).
** exception error: bad argument
     in function  io:format/3
        called as io:format(<0.50.0>,"The average equals
~n",2.4285714285714284)


Why am I getting '**exception error:'?

Thank you, I hope this isn't too newbie a question.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170221/44365945/attachment.htm>


More information about the erlang-questions mailing list