IDENTIFICATION DIVISION
PROGRAM-ID. ARITHMETIC OPERATIONS.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 OPR PIC X.
88 ADDITION VALUE "+".
88 SUBTRACTION VALUE "-".
88 MULT VALUE "*".
88 DIVI VALUE "/".
88 EXT VALUE "E".
88 VALID-VALUES VALUES ARE "+" "-" "*" "/" "E".
77 A PIC S999V99.
77 B PIC S999V99.
77 RESULT PIC -9999.99.
PROCEDURE DIVISION.
INP-PARA.
DISPLAY "ENTER TWO NUMBERS".
ACCEPT A.
ACCEPT B.
MENU-PARA. PPPPP
DISPLAY "MENU".
DISPLAY "ADDITION(+)".
DISPLAY "SUBTRACTION(-)".
DISPLAY "MULTIPLICATION(*)".
DISPLAY "DIVISION(/)".
DISPLAY "EXIT(E)".
DISPLAY "ENTER THE OPERATOR".
ACCEPT OPR.
IF ADDITION
COMPUTE RESULT = A + B.
IF SUBTRACTION
COMPUTE RESULT = A - B.
IF MULT
COMPUTE RESULT = A * B.
IF EXT GO TO ERR-PARA.
IF DIVI
IF B = 0
DISPLAY "DIVISION BY ZERO" GO TO ERR-PARA
ELSE
COMPUTE RESULT = A / B.
IF NOT VALID-VALUES
DISPLAY "WRONG CHOICE" GO TO MENU-PARA.
IF RESULT = 0
DISPLAY 0.
DISPLAY "RESULT= ", RESULT GO TO MENU-PARA.
ERR-PARA.
STOP-RUN.
.
PROGRAM-ID. ARITHMETIC OPERATIONS.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 OPR PIC X.
88 ADDITION VALUE "+".
88 SUBTRACTION VALUE "-".
88 MULT VALUE "*".
88 DIVI VALUE "/".
88 EXT VALUE "E".
88 VALID-VALUES VALUES ARE "+" "-" "*" "/" "E".
77 A PIC S999V99.
77 B PIC S999V99.
77 RESULT PIC -9999.99.
PROCEDURE DIVISION.
INP-PARA.
DISPLAY "ENTER TWO NUMBERS".
ACCEPT A.
ACCEPT B.
MENU-PARA. PPPPP
DISPLAY "MENU".
DISPLAY "ADDITION(+)".
DISPLAY "SUBTRACTION(-)".
DISPLAY "MULTIPLICATION(*)".
DISPLAY "DIVISION(/)".
DISPLAY "EXIT(E)".
DISPLAY "ENTER THE OPERATOR".
ACCEPT OPR.
IF ADDITION
COMPUTE RESULT = A + B.
IF SUBTRACTION
COMPUTE RESULT = A - B.
IF MULT
COMPUTE RESULT = A * B.
IF EXT GO TO ERR-PARA.
IF DIVI
IF B = 0
DISPLAY "DIVISION BY ZERO" GO TO ERR-PARA
ELSE
COMPUTE RESULT = A / B.
IF NOT VALID-VALUES
DISPLAY "WRONG CHOICE" GO TO MENU-PARA.
IF RESULT = 0
DISPLAY 0.
DISPLAY "RESULT= ", RESULT GO TO MENU-PARA.
ERR-PARA.
STOP-RUN.
.
No comments:
Post a Comment