Small Calculator I made for myself while trying to learn COBOL for fun. Compiler used is GNUCOBOL. Just asks for input and will either do multiplication, subtraction, or addition. Completes run after input is asked.
MATH
IDENTIFICATION DIVISION.
PROGRAM-ID. MATH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP PIC A(14).
01 NUM1 PIC 9(7).
01 NUM2 PIC A(2).
88 PLU VALUE "+".
88 AIDS VALUE "-".
88 MULT VALUE "*".
01 NUM3 PIC 9(15).
01 ANS PIC 9(8).
PROCEDURE DIVISION.
DISPLAY "Input: "
ACCEPT INP.
UNSTRING INP DELIMITED BY SPACE
INTO NUM1, NUM2, NUM3
END-UNSTRING.
IF NUM2 = "+" THEN
ADD NUM1 NUM3 GIVING ANS
ELSE
IF NUM2 = "-" THEN
SUBTRACT NUM1 FROM NUM3 GIVING ANS
ELSE
IF NUM2 = "*" THEN
MULTIPLY NUM1 BY NUM3 GIVING ANS
END-IF.
DISPLAY ANS.
STOP RUN.
COBOL documentation isn't as great compares to languages like C++ or Javascript, so I struggled a bit.