Created
June 19, 2013 23:59
-
-
Save jamesmichiemo/5819206 to your computer and use it in GitHub Desktop.
Conditional expressions in Ruby language
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 | |
# | |
print "How many degrees is the temperature right now? " | |
degrees = gets.chomp().to_f | |
print "Fahrenheit(F) or Celsius(C)? " | |
unit = gets.chomp().to_s | |
convertC = (degrees * 9)/5 + 32 | |
convertF = (degrees - 32) * 5 / 9 | |
if unit == "C" || unit == "c" || unit == "Celsius" || unit == "celsius" | |
puts "The temperature is #{convertC} degrees Fahrenheit." | |
elsif unit == "F" || unit == "f" || unit == "Fahrenheit" || unit == "fahrenheit" | |
puts "The temperature is #{convertF} degrees Celsius." | |
else | |
puts "The unit given for temperature is invalid" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment