Skip to content

Instantly share code, notes, and snippets.

@hhimanshu
Created December 16, 2014 20:33
Show Gist options
  • Save hhimanshu/33a581fd0c22f7d43220 to your computer and use it in GitHub Desktop.
Save hhimanshu/33a581fd0c22f7d43220 to your computer and use it in GitHub Desktop.
Erlang: Temperature Conversion
% http://www.erlang.org/course/exercises.html
% Write functions temp:f2c(F) and temp:c2f(C) which convert between centigrade and Fahrenheit scales. (hint 5(F-32) = 9C)
-module(temp).
-export([c2f/1, f2c/1, convert/1]).
c2f(C) -> (C *9/5) + 32.
f2c(F) -> (F - 32) * 5/9.
convert({From, What}) ->
case {From, What} of
{c, What} -> c2f(What);
{f, What} -> f2c(What);
{_, _} -> io:format("incorrect format~n")
end.
@JaganNampally
Copy link

Thanks for the code. But how to take input( fread , read, etc) in start() function and pass it the convert() function. Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment