-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.cob
31 lines (30 loc) · 881 Bytes
/
math.cob
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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 "MATHS AND THINGS: $"
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.