Programming Fundamentals/Functions/Ruby: Difference between revisions

From Wikiversity
Jump to navigation Jump to search
Content deleted Content added
Creating
(No difference)

Revision as of 15:48, 22 January 2017

subroutines.rs

def get_f()
    puts "Enter Fahrenheit temperature:"
    f = gets.chomp.to_f
        
    return f
end

def calculate_c(f)
    c = (f - 32) * 5 / 9
        
    return c
end

def display_result(f, c)
    puts (f).to_s + "° Fahrenheit is " + (c).to_s + "° Celsius"
end

def main()
    f = get_f()
    c = calculate_c(f)
    display_result(f, c)
end

main()

Try It

Copy and paste the code above into one of the following free online development environments or use your own Ruby compiler / interpreter / IDE.

See Also