• Home
  • Chemistry
  • Astronomy
  • Energy
  • Nature
  • Biology
  • Physics
  • Electronics
  • COBOL Program to Convert Celsius to Fahrenheit - Code & Explanation
    ```cobol

    IDENTIFICATION DIVISION.

    PROGRAM-ID. CENTIGRADE-TO-FAHRENHEIT.

    DATA DIVISION.

    WORKING-STORAGE SECTION.

    01 CENTIGRADE-VALUE PIC 99V99.

    01 FAHRENHEIT-VALUE PIC 99V99.

    PROCEDURE DIVISION.

    DISPLAY "Enter the temperature in Centigrade (C): ".

    ACCEPT CENTIGRADE-VALUE.

    COMPUTE FAHRENHEIT-VALUE = (CENTIGRADE-VALUE * 9 / 5) + 32.

    DISPLAY "The temperature in Fahrenheit (F) is: ", FAHRENHEIT-VALUE.

    STOP RUN.

    ```

    Explanation:

    1. IDENTIFICATION DIVISION: Contains the program ID, which is "CENTIGRADE-TO-FAHRENHEIT".

    2. DATA DIVISION:

    - WORKING-STORAGE SECTION:

    - CENTIGRADE-VALUE: A variable to store the temperature in Centigrade.

    - FAHRENHEIT-VALUE: A variable to store the temperature in Fahrenheit.

    3. PROCEDURE DIVISION:

    - DISPLAY "Enter the temperature in Centigrade (C): ": Prompts the user to enter the temperature in Centigrade.

    - ACCEPT CENTIGRADE-VALUE: Reads the user input and stores it in the "CENTIGRADE-VALUE" variable.

    - COMPUTE FAHRENHEIT-VALUE = (CENTIGRADE-VALUE * 9 / 5) + 32: Calculates the Fahrenheit temperature using the conversion formula.

    - DISPLAY "The temperature in Fahrenheit (F) is: ", FAHRENHEIT-VALUE: Displays the converted Fahrenheit temperature.

    - STOP RUN: Ends the program execution.

    How to run this program:

    1. Compile: Use a COBOL compiler to compile the program.

    2. Execute: Run the compiled program.

    3. Input: The program will prompt you to enter the temperature in Centigrade.

    4. Output: The program will display the temperature in Fahrenheit.

    Example:

    If you enter 25.00 as the temperature in Centigrade, the program will output:

    ```

    The temperature in Fahrenheit (F) is: 77.00

    ```

    Science Discoveries © www.scienceaq.com