Programming Fundamentals/Functions/Lua: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
Creating |
(No difference)
|
Revision as of 02:17, 20 January 2017
subroutines.lua
function get_f()
local f
print("Enter Fahrenheit temperature:")
f = tonumber(io.read())
return f
end
function calculate_c(f)
local c
c = (f - 32) * 5 / 9
return c
end
function display_result(f, c)
print(f .. "° Fahrenheit is " .. c .. "° Celsius")
end
function main()
local f
local c
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 Lua compiler / interpreter / IDE.