DIVIDE with REMAINDER in COBOL
One DIVIDE fills the boxes and the basket: quotient and remainder in a single verb.
IDENTIFICATION DIVISION.
PROGRAM-ID. DIVIDE-REMAINDER.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 EGG-COUNT PIC 9(3) VALUE 157.
01 BOX-SIZE PIC 99 VALUE 12.
01 FULL-BOXES PIC 99.
01 LEFT-OVER PIC 99.
PROCEDURE DIVISION.
DIVIDE EGG-COUNT BY BOX-SIZE
GIVING FULL-BOXES REMAINDER LEFT-OVER
ON SIZE ERROR DISPLAY "box math overflowed"
END-DIVIDE
DISPLAY EGG-COUNT " eggs fill " FULL-BOXES " boxes"
DISPLAY LEFT-OVER " stay in the basket"
STOP RUN.
How it works
DIVIDE ... GIVING FULL-BOXES REMAINDER LEFT-OVERnames both results.ON SIZE ERRORguards the arithmetic;END-DIVIDEcloses the scope.- 157 eggs by the dozen: 13 boxes and one egg still in the basket.
Keywords and builtins used here
DATADISPLAYDIVIDEDIVISIONIDENTIFICATIONPROCEDURESECTIONSTOP
The run, in numbers
- Lines
- 16
- Characters to type
- 453
- Tokens
- 61
- Three-star pace
- 40 tpm
At the three-star pace of 40 tokens a minute, this run takes about 92 seconds.
Step 3 of 3 in Arithmetic, step 12 of 27 in Language basics.