Back
Close

Elixir - Conversor Celsius - Farenheit (version 2)

mat130517
1,502 views

Conversor Celsius - Farenheit

Programa conversor. Prueba para curso iniciación a Elixir página web.

defmodule Funciones do
def convertir(tipo, grados) do
grados
|> formula(tipo) # es como si fuera formula(grados,:tipo)
|> redondear
|> cadenapantalla
|> IO.puts
end
defp formula(num,select) do
case select do
:aCel -> (num-32) * 5/9
:aFah -> (num * 9/5) +32
end
end
defp redondear(num), do: Float.round(num,2)
defp cadenapantalla(num) do
"El resultado es " <> Float.to_string(num) <> " Fahranheit"
end
end
Funciones.convertir(:aCel,40)
Funciones.convertir(:aFah,10)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Tech.io mola mucho, pero mucho mucho !

If you want a more complex example (external libraries, viewers...), use the Advanced Elixir template

Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants