कंप्यूटर प्रोग्रामिंग/कंडीशन/लुआ

विकिविश्वविद्यालय से

conditions.lua[सम्पादन | स्रोत सम्पादित करें]

-- This program asks the user to select Fahrenheit or Celsius conversion
-- and input a given temperature. Then the program converts the given
-- temperature and displays the result.

function to_celsius()
    local f
    local c
    
    io.write("Enter Fahrenheit temperature:", "\n")
    f = tonumber(io.read())
    c = (f - 32) * 5 / 9
    io.write(f, "° Fahrenheit is ", c, "° Celsius", "\n")
end

function to_fahrenheit()
    local c
    local f
    
    io.write("Enter Celsius temperature:", "\n")
    c = tonumber(io.read())
    f = c * 9 / 5 + 32
    io.write(c, "° Celsius is ", f, "° Fahrenheit", "\n")
end

function if_else()
    local choice
    
    io.write("Enter F to convert to Fahrenheit or C to convert to Celsius:", "\n")
    choice = io.read()
    if choice == "C" or choice == "c" then
        to_celsius()
    elseif choice == "F" or choice == "f" then
            to_fahrenheit()
    else
        io.write("You must enter C to convert to Celsius or F to convert to Fahrenheit!", "\n")
    end
end

function main()
    if_else()
end

main()

कोशिश करो[सम्पादन | स्रोत सम्पादित करें]

निम्न कोड मुफ्त ऑनलाइन विकास के वातावरण में से एक में ऊपर कॉपी और पेस्ट करो या अपने खुद के कम्पाइलर/इंटरप्रेटर/आईडीई का उपयोग करें।

यह भी देखें[सम्पादन | स्रोत सम्पादित करें]