Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My first ruby program
#1
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!"
[Image: izsyo6.jpg]


Reply
#2
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
At the top will be the same place you hang from.
Reply
#3
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
Reply
#4
Good to see you giving it a go Big Grin
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting Started With Ruby eax 7 4,738 12-13-2012, 10:03 AM
Last Post: L-Carnitine
  [Tut] How to install Ruby on Mac, Windows and Linux Jordan L. 13 7,616 12-13-2012, 07:49 AM
Last Post: L-Carnitine
  Ruby eBook sockatobi 7 2,784 12-13-2012, 07:48 AM
Last Post: L-Carnitine
  what is ruby on rails DaUB3R 3 1,855 11-01-2012, 04:20 AM
Last Post: johnnymward
  Should I Start Ruby? BreShiE 13 5,033 11-13-2011, 04:14 PM
Last Post: Speedy

Forum Jump:


Users browsing this thread: 1 Guest(s)