cleaned up with pipes
This commit is contained in:
parent
683f5f5dfa
commit
ac76d8d69a
23
convert.ex
Normal file
23
convert.ex
Normal file
@ -0,0 +1,23 @@
|
||||
# Unit Converter
|
||||
# Sean Smith 08/19/2022
|
||||
# sean@spacealien.xyz
|
||||
|
||||
# anonymous function to convert celcius to farenheit. returns float
|
||||
c_to_f = fn c -> c * 9 / 5 + 32 end
|
||||
|
||||
# anonymous function to convert farenheit to celcius. returns float
|
||||
f_to_c = fn f -> (f - 32) * 5 / 9 end
|
||||
|
||||
IO.puts("Convert Celcius -> Farenheit -OR- Farenheit -> Celcius")
|
||||
IO.puts("1) C->F ")
|
||||
IO.puts("2) F->C")
|
||||
|
||||
argv1 = IO.gets("Enter selection number: ") |> String.trim() |> String.to_integer()
|
||||
|
||||
argv2 = IO.gets("Enter temperature: ") |> String.trim() |> String.to_float()
|
||||
|
||||
case argv1 do
|
||||
1 -> IO.puts(c_to_f.(argv2))
|
||||
2 -> IO.puts(f_to_c.(argv2))
|
||||
true -> {:error, "bad input"}
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user