MULTIPLY and DIVIDE
Part of the Data and Numbers section of Coddy's COBOL Programming journey. Lesson 13 of 23.
MULTIPLY and DIVIDE work like ADD: the result replaces the last field named.
MULTIPLY 3 BY QTY. *> QTY * 3
DIVIDE 4 INTO TOTAL. *> TOTAL / 4DIVIDE a INTO b divides b by a. It reads like English: divide 4 into the total.
The operand after BY or INTO receives the result, so it has to be a field. MULTIPLY QTY BY 3 stops the compiler: 3 cannot hold a result.
The result is cut to fit the field like any other: with TOTAL at 10 and no decimals, DIVIDE 4 INTO TOTAL stores 2.
Challenge
EasyRead QTY and PRICE, then use MULTIPLY so PRICE holds the price times the quantity. The program prints it: 3 at 12 gives Total: 0036.
Example input, one line per ACCEPT: 3, 12.
Try it yourself
IDENTIFICATION DIVISION.
PROGRAM-ID. MULT.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 QTY PIC 9(2).
01 PRICE PIC 9(4).
PROCEDURE DIVISION.
ACCEPT QTY.
ACCEPT PRICE.
*> Multiply PRICE by QTY here
DISPLAY "Total: " PRICE.
STOP RUN.