Pages - GamesandApps

Cobol Program for a Simple Calculator

Building a Primitive Calculator in Cobol :-


        IDENTIFICATION DIVISION.
        PROGRAM-ID. CALC.
        ENVIRONMENT DIVISION.
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 A PIC 9999 VALUE ZERO.
        01 B PIC 9999 VALUE ZERO.
        01 C PIC 9999 VALUE ZERO.
        01 M PIC A(3).
        PROCEDURE DIVISION.
        MAIN-PARA.
            DISPLAY "ENTER 1ST NUMBER :".
            ACCEPT A.
            DISPLAY "ENTER 2ND NUMBER :".
            ACCEPT B.
            DISPLAY "ENTER ACTION: ADD/SUB/MUL/DIV :"
            ACCEPT S.
            IF S = "ADD" OR "add"
            COMPUTE C = A + B.
            IF S = "SUB" OR "sub"
            COMPUTE C = A - B.
            IF S = "MUL" OR "mul"
            COMPUTE C = A * B.
            IF S = "DIV" OR "div"
            COMPUTE C = A  / B.
            DISPLAY "REQUIRED RESULT : " C.
            STOP RUN.

Output-
Cobol Program for a Simple Calculator - Output
Output - Cobol Code to Create a Calculator

           

No comments:

Post a Comment