Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

32 lines (24 sloc) 1.029 kb
=begin
~\rubylearning\p006fahr_to_cel.rb
Developer: Dan Chuparkoff (Twitter: @chuparkoff )
Creation Date: 4/13/2012
Initial Ruby Version: Ruby 1.9.3-p125
Initial Development Environment: Windows 7 Home Premium - SP1
Initial Development IDE: Jetbrains RubyMine 4.0.3
This program was created as an exercise in the RubyLearning PORPC101-32C Course.
http://rubylearning.com
This program illustrates extends our use of gets and chomp.
=end
#Variable Initialization
temp_in_fahrenheit = ""
temp_in_celsius = ""
#Main
#Collect the Temp from the STDOUT and chomp the /n character.
puts 'Enter temperature in Fahrenheit: '
STDOUT.flush
temp_in_fahrenheit = gets.chomp
#Convert the Fhar. String to Float, then Convert the Value into Celcius
temp_in_celsius = (((temp_in_fahrenheit.to_f - 32.0) / 9.0) * 5.0)
#Display the converted Celcius float in 2 decimal places wrapped in output copy
puts 'Temperature ' + temp_in_fahrenheit + ' degree Fahrenheit = ' + \
format("%.2f", temp_in_celsius) + ' degree Celsius'
Jump to Line
Something went wrong with that request. Please try again.