कंप्यूटर प्रोग्रामिंग/कंडीशन/बेसिक

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

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

' 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.

DECLARE SUB Main
DECLARE SUB IfElse
DECLARE SUB SelectCase
DECLARE SUB ToCelsius
DECLARE SUB ToFahrenheit

Main

SUB Main
    IfElse
    SelectCase
END SUB

SUB IfElse
    DIM Choice$
    
    PRINT "Enter F to convert to Fahrenheit or C to convert to Celsius:"
    INPUT Choice$
    IF Choice$ = "C" OR Choice$ = "c" THEN
        ToCelsius 
    ELSEIF Choice$ = "F" OR Choice$ = "f" THEN
            ToFahrenheit 
    ELSE
        PRINT "You must enter C to convert to Celsius or F to convert to Fahrenheit!"
    END IF
END SUB

SUB SelectCase
    DIM Choice$
    
    PRINT "Enter F to convert to Fahrenheit or C to convert to Celsius:"
    INPUT Choice$
    SELECT CASE Choice$
        CASE "C"
            ToCelsius
        CASE "c"
            ToCelsius
        CASE "F"
            ToFahrenheit
        CASE "f"
            ToFahrenheit
        CASE ELSE
            PRINT "You must enter C to convert to Celsius or F to convert to Fahrenheit!"
    END SELECT
END SUB

SUB ToCelsius
    DIM F
    DIM C
    
    PRINT "Enter Fahrenheit temperature:"
    INPUT F
    C = (F - 32) * 5 / 9
    PRINT STR$(F) + "° Fahrenheit is " + STR$(C) + "° Celsius"
END SUB

SUB ToFahrenheit
    DIM C
    DIM F
    
    PRINT "Enter Celsius temperature:"
    INPUT C
    F = C * 9 / 5 + 32
    PRINT STR$(C) + "° Celsius is " + STR$(F) + "° Fahrenheit"
END SUB

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

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

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