While reading through Ruby for Rails by David A. Black, I had the chance to practice and work ahead on a small but applicable program that converts Fahrenheit to Celsius. Well, the book actually does it the other way around, but I like to tweak programs my way to test my own understanding of how it functions.
It was a quick program to write in < 30 minutes and a nice refresher on F & C formulas:
# ask for a number in Fahrenheit puts 'Convert Fahrenheit to Celsius. Please enter a Fahrenheit temperature:' # get a number from the user f = gets.chomp # apply the conversion formula from F to C c = (f.to_i - 32) * 5 / 9 # output the formula in string to the user puts f.to_s + 'F is ' + c.to_s + 'C.'
This program is a nod to my older brother who lives in Taiwan and constantly tells me his location’s temperature in Celsius. It should be noted that he is also the one who first encouraged me to learn Ruby. Thanks, Tim!