Menu
CoddyTech

The Receipt

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

challenge icon

Challenge

Easy

Finish the receipt: print RECEIPT first, then the line, then the tax (20% of the line total) and the total. For the example input those two lines are Tax: 0002.70 and Total: 0016.20.

Example input, one line per ACCEPT: Coffee, 4.50, 3.

Try it yourself

       IDENTIFICATION DIVISION.
       PROGRAM-ID. RECEIPT.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 ITEM PIC X(12).
       01 PRICE PIC 9(3)V99.
       01 QTY PIC 99.
       01 LINE-TOTAL PIC 9(4)V99.
       01 TAX PIC 9(4)V99.
       01 TOTAL PIC 9(4)V99.
       01 PRICE-OUT PIC 9(3).99.
       01 MONEY-OUT PIC 9(4).99.
       PROCEDURE DIVISION.
           ACCEPT ITEM.
           ACCEPT PRICE.
           MOVE PRICE TO PRICE-OUT.
           ACCEPT QTY.
           COMPUTE LINE-TOTAL = QTY * PRICE.
           MOVE LINE-TOTAL TO MONEY-OUT.
           DISPLAY ITEM QTY " x " PRICE-OUT
               " = " MONEY-OUT.
           *> Add the heading, the tax and the total
           STOP RUN.

All lessons in First Programs