Support Forums

Full Version: My first ruby program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!"
I said it on my website, and I'll say it here. Really nice program mate, better then half the stuff I can do now as a programmer, and this is only your first. Big Grin
Tried it out, looks good. Very powerful for the few functions you used. I'm going to try that Ruby in 20 minutes tomorrow Big Grin
Good to see you giving it a go Big Grin