Skip to content

Instantly share code, notes, and snippets.

@jamesmichiemo
Created June 19, 2013 23:59
Show Gist options
  • Save jamesmichiemo/5819206 to your computer and use it in GitHub Desktop.
Save jamesmichiemo/5819206 to your computer and use it in GitHub Desktop.
Conditional expressions in Ruby language
# 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