24 lines
657 B
Elixir
24 lines
657 B
Elixir
# 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
|