03-13-2010, 10:05 PM
I have decided to start learning ruby. So far all I have learned is if and end statements, the difference between print and puts, getting user input, and type conversion, so I made this. It is a temperature converter that will convert any temperature, it is basically just a copy of one of my old python scripts, except in ruby!
Code:
puts 'For Farenheit to Celsius, Press:1'
puts 'For Farenheit to Kelvin, Press:2'
puts 'For Celsius to Farenheit, Press:3'
puts 'For Celsius to Kelvin, Press:4'
puts 'For Kelvin to Celsius, Press:5'
puts 'For Kelvin to Farenheit, Press:6'
print 'Please enter a choice =>'
STDOUT.flush
choice = gets.chomp
if choice == "1":
print "Enter your degrees Farenheit here:"
a = gets.chomp
a = a.to_f
puts (a - 32) * 5/9
end
if choice == "2":
print "Enter your degrees Farenheit here:"
a = gets.chomp
a = a.to_f
puts (a - 32) * 5/9 + 273
end
if choice == "3":
print "Enter your degrees Celsius here:"
a = gets.chomp
a = a.to_f
puts a * 9/5 + 32
end
if choice == "4":
print "Enter your degrees Celsius here:"
a = gets.chomp
a = a.to_f
puts a + 273
end
if choice == "5":
print "Enter your degrees Kelvin here:"
a = gets.chomp
a = a.to_f
puts a - 273
end
if choice == "6":
print "Enter your degrees Kelvin here:"
a = gets.chomp
a = a.to_f
puts (a - 273) * 9/5 + 32
end
puts "Thank you for using my program!"