Created
December 16, 2014 20:33
-
-
Save hhimanshu/33a581fd0c22f7d43220 to your computer and use it in GitHub Desktop.
Erlang: Temperature Conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the code. But how to take input( fread , read, etc) in start() function and pass it the convert() function. Thanks in advance