-
-
Save stianeklund/615db7e8f324d6de951c to your computer and use it in GitHub Desktop.
temperature converter
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
# 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