Menu
CoddyTech

GIVING

Part of the Data and Numbers section of Coddy's COBOL Programming journey. Lesson 14 of 23.

GIVING stores a result in another field and leaves the operands as they were:

ADD PRICE TAX GIVING TOTAL.

Each verb takes it:

SUBTRACT DISCOUNT FROM PRICE
    GIVING NET.
MULTIPLY QTY BY PRICE GIVING AMT.
DIVIDE TOTAL BY 12 GIVING MONTHLY.

With GIVING, any operand can be a literal, since none of them receives the result. DIVIDE ... BY exists only with GIVING.

ADD with GIVING can add several values at once, and the GIVING field can be edited, so a result goes straight into a picture for printing:

01 SUM-OUT PIC ZZZ9.
    ADD A B C GIVING SUM-OUT.
challenge icon

Challenge

Easy

Read PRICE and DISCOUNT, and store the price minus the discount in NET with SUBTRACT and GIVING. The program prints all three, so PRICE must keep its value: 050 - 008 = 042.

Example input, one line per ACCEPT: 50, 8.

Try it yourself

       IDENTIFICATION DIVISION.
       PROGRAM-ID. NETS.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 PRICE PIC 9(3).
       01 DISCOUNT PIC 9(3).
       01 NET PIC 9(3).
       PROCEDURE DIVISION.
           ACCEPT PRICE.
           ACCEPT DISCOUNT.
           *> Store PRICE minus DISCOUNT in NET
           DISPLAY PRICE " - " DISCOUNT " = " NET.
           STOP RUN.

All lessons in Data and Numbers