Wednesday, December 13, 2017

Celsius To Fahrenheit Converter in Ruby

Here is a sample program that will ask the user to give a value in temperature in Celsius and it will converted into Fahrenheit equivalent in Ruby. I created a method in this example to compute the Fahrenheit equivalent.

 I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.





Sample Program Output


Program Listing

temp.rb


# temp.rb
# Written By: Mr. Jake R. Pomperada, MAED-IT
# December 13, 2017
# Tool : Ruby and Sublime Text Editor
# Location : Bacolod City, Negros Occidental Philippines

# method to celsius to fahrenheit

def convert_temp(celsius)
  fahrenheit = (celsius.to_f * 9 / 5) + 32
  print "\n\n"
  print "The equivalent is: #{fahrenheit.round(2)} degrees fahrenheit."
  print "\n\n"
end

celsius_input =""
answer = ""

until answer.downcase == "n" do 
print "\n\n"
print "===== CELSIUS TO FAHRENHEIT CONVERTER IN RUBY ====="
print "\n\n"
print "Created by Mr. Jake R. Pomperada"
print "\n\n"
print "Give temperature in celsius : "
celsius_input = gets.to_i

convert_temp(celsius_input)

print "\n"
print "Do you want to continue Y/N ? : "
answer= gets.chop
end  
print "\n\n"
    print "End of Program"
    print "\n\n"




No comments:

Post a Comment