Menu
CoddyTech

A First COMPUTE

Part of the First Programs section of Coddy's COBOL Programming journey. Lesson 14 of 19.

COMPUTE works out a formula and stores the result:

COMPUTE ROOM-AREA = WIDE * LONG.

The operators are +, -, *, / and ** for a power. Put a space on both sides of each one: WIDE-LONG is read as one name, WIDE - LONG as a subtraction.

Parentheses group parts of a formula, as in math:

COMPUTE AVERAGE = (A + B) / 2.

The result keeps only the digits its field has room for. 7 divided by 2 into a whole-number field stores 3: the fraction is dropped, not rounded.

challenge icon

Challenge

Easy

Read WIDE and then LONG, compute ROOM-AREA as their product, and display Area: followed by it.

Example input, one line per ACCEPT: 4, 5.

Try it yourself

       IDENTIFICATION DIVISION.
       PROGRAM-ID. AREAS.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WIDE PIC 9(3).
       01 LONG PIC 9(3).
       01 ROOM-AREA PIC 9(6).
       PROCEDURE DIVISION.
           *> Read, compute, display
           STOP RUN.

All lessons in First Programs