I was teaching some new people in office a bit of COBOL, so I threw together this exercise where they had to write a program that would generate the first 10 numbers of a Fibonacci suite and then test them against the rules of fizzbuzz.
I was hoping to get an honest review of this code to see how I could improve.
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG6.
AUTHOR. SAGGING RUFUS.
DATE-WRITTEN. JUNE 5 2017.
DATE-COMPILED.
TITLE "FIZZBUZZONACCI"
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. AMDAHL-580.
OBJECT-COMPUTER. AMDAHL-580.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-STORAGE.
05 WS-SUB PIC 9(8) COMP.
05 WS-LIMIT PIC 9(4) VALUE 10.
05 WS-F.
10 WS-FX PIC 9(8) COMP.
10 WS-F1 PIC 9(8) COMP VALUE 0.
10 WS-F2 PIC 9(8) COMP VALUE 1.
05 WS-F-ARRAY PIC 9(8) COMP OCCURS 10 TIMES.
05 WS-F-SUB PIC 9(8) COMP VALUE 0.
01 COUNTERS.
05 CURRENT-NUM PIC 9(3) COMP.
01 REMAINDERS.
05 MOD-THREE PIC 99 COMP.
88 FIZZ VALUE 0.
05 MOD-FIVE PIC 99 COMP.
88 BUZZ VALUE 0.
PROCEDURE DIVISION.
0000-MAINLINE.
PERFORM VARYING WS-SUB
FROM 1 BY 1
UNTIL WS-SUB > WS-LIMIT
COMPUTE
WS-FX = WS-F1 + WS-F2
END-COMPUTE
ADD 1 TO WS-F-SUB
MOVE WS-F2 TO WS-F1
MOVE WS-FX TO WS-F2
MOVE WS-FX TO WS-F-ARRAY(WS-F-SUB)
END-PERFORM
PERFORM VARYING WS-SUB
FROM 1 BY 1
UNTIL WS-SUB > WS-LIMIT
MOVE WS-F-ARRAY(WS-SUB) TO CURRENT-NUM
COMPUTE
MOD-THREE = FUNCTION MOD(CURRENT-NUM 3)
END-COMPUTE
COMPUTE
MOD-FIVE = FUNCTION MOD (CURRENT-NUM 5)
END-COMPUTE
EVALUATE TRUE
WHEN FIZZ AND BUZZ
DISPLAY "FIZZBUZZ"
WHEN FIZZ
DISPLAY "FIZZ"
WHEN BUZZ
DISPLAY "BUZZ"
WHEN OTHER
DISPLAY CURRENT-NUM
END-EVALUATE
END-PERFORM
STOP RUN.