[erlang-questions] feedback please

Roelof Wobben r.wobben@REDACTED
Wed Sep 23 22:30:33 CEST 2015


I did chapter 4 of Programming Erlang  which is about pattern matching.

So as a challenge I tried to make a little cash on hands programm.

Here is the code :



get_balance(Balance)  ->
     io:format("Your account balance is $~w.~n",  [Balance]),
     Entered_action  =  io:get_line("Which Action do you need (w)ithdraw/(d)eposit? "),
     Action  =  string:strip(Entered_action,  right,  $\n),  
     Entered_amount  =  io:get_line("Which Amount do you want to withdraw/deposit? "),
     Amount2  =  string:to_integer(string:strip(Entered_amount,  right,  $\n)),
     Amount  =  element(1,Amount2),

     get_balance(Balance,  {Action,  Amount}).

get_balance(0,{"w",_  })  ->
     io:format("You have no funds to withdraw"),  
get_balance(Balance,  {"w",  Amount})  when  Amount   >  Balance  ->
     io:format("You cannot withdraw more then you have"),  

get_balance(Balance,  {"w",  Amount})  ->  
     get_balance(Balance  -  Amount);
get_balance(Balance, {"d", Amount}) -> get_balance(Balance + Amount); 
Are there things I could do better without processes or OTP because they 
are still not explained. Roelof

More information about the erlang-questions mailing list