Support Forums
My first ruby program - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Ruby and Ruby on Rails (https://www.supportforums.net/forumdisplay.php?fid=55)
+---- Thread: My first ruby program (/showthread.php?tid=5266)



My first ruby program - uber1337 - 03-13-2010

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!"



RE: My first ruby program - Jordan L. - 03-14-2010

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


RE: My first ruby program - nevets04 - 03-14-2010

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


RE: My first ruby program - Wolskie - 03-15-2010

Good to see you giving it a go Big Grin