I am creating a program that serves as a temperature converter (CELSIUS TO KELVIN and VICE VERSA). But I'm having trouble with my codes (or maybe there's a problem in the compiler. Idk). At first, I thought that I was using a wrong formula. But as I checked the input that's being stored in a variable by displaying it, it's just showing only one digit of the input. For example.. My input was 15, it only takes '1'.. Or let's say 45, it only takes '4'.. I declared the input like this:
01 CELSIUS PIC S9(2)V99.
With my examples above, it gives me: 01.00 or 04.00 Please help.
IDENTIFICATION DIVISION. ------------------
PROGRAM-ID. temp.
ENVIRONMENT DIVISION. ------------------
CONFIGURATION SECTION.
*-----------------------
INPUT-OUTPUT SECTION. *-----------------------
DATA DIVISION. ------------------
FILE SECTION. *-----------------------
WORKING-STORAGE SECTION.
01 TEMP-CELSIUS PIC S9(2)V99.
01 CELSIUS-RESULT PIC +ZZ9.99.
01 TEMP-KELVIN PIC S9(2)V99.
01 KELVIN-RESULT PIC +ZZ9.99.
01 VAR-OPTION PIC X.
01 X PIC S9(5)V99.
*-----------------------
PROCEDURE DIVISION.
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
MAIN-PROCEDURE.
**
* The main procedure of the program
**
DISPLAY 'OPTION 1: CELSIUS TO KELVIN'
DISPLAY 'OPTION 2: KELVIN TO CELSIUS'
DISPLAY 'ENTER YOUR OPTION: '
ACCEPT VAR-OPTION
MOVE +273.15 TO X
IF VAR-OPTION = '1'
DISPLAY 'ENTER CELSIUS: '
ACCEPT TEMP-CELSIUS
DISPLAY TEMP-CELSIUS
ADD X TEMP-CELSIUS GIVING KELVIN-RESULT
DISPLAY KELVIN-RESULT
ELSE
IF VAR-OPTION = '2'
DISPLAY 'ENTER KELVIN: '
ACCEPT TEMP-KELVIN
DISPLAY TEMP-KELVIN
SUBTRACT X FROM TEMP-KELVIN GIVING CELSIUS-RESULT
DISPLAY CELSIUS-RESULT
END-IF
STOP RUN.
** add other procedures here
END PROGRAM temp.