Skip to content

Instantly share code, notes, and snippets.

@stianeklund
Last active August 29, 2015 14:02
Show Gist options
  • Save stianeklund/615db7e8f324d6de951c to your computer and use it in GitHub Desktop.
Save stianeklund/615db7e8f324d6de951c to your computer and use it in GitHub Desktop.
temperature converter
# Temperature converter
# Made by Stian
#
puts "Convert from Celsius to Fahrenheit or Fahreinheit to Celsius"
puts "Please select 1 for Celsius or 2 for Fahrenheit"
selection = gets.to_i
# Conversion formulas
# °F = (°C · 9/5) + 32
# °C = (°F − 32) · 5/9
#
if selection == "1"
puts "Enter Celsius value: "
celsius = gets.to_f
fahrenheit = (celsius * 9 / 5) + 32
puts "Your Fahrenheit value is: #{fahrenheit}."
elsif selection == "2"
puts "Enter Fahrenheit value: "
fahrenheit = gets.to_f
celsius = (fahrenheit - 32) * 5 / 9
puts "Your Celsius value is: #{celsius}."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment