The Schedule Loop
Part of the Decisions and Loops section of Coddy's COBOL Programming journey. Lesson 18 of 20.
Challenge
EasyNow read a monthly PAYMENT and perform PAY-MONTH until the balance is zero. Each month adds 1 to MONTH-NO, adds the interest to the balance, then takes off the payment, or the whole balance when it is smaller. Print Month 1 interest 10.00 for each month.
Example input, one line per ACCEPT: 1000, 12, 300.
Try it yourself
IDENTIFICATION DIVISION.
PROGRAM-ID. LOAN.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 AMOUNT PIC 9(5).
01 RATE PIC 99.
01 BALANCE PIC 9(6)V99.
01 INTEREST PIC 9(4)V99.
01 OUT-INT PIC Z,ZZ9.99.
01 PAYMENT PIC 9(5).
01 MONTH-NO PIC 99 VALUE ZERO.
01 OUT-MONTH PIC Z9.
PROCEDURE DIVISION.
MAIN-PARA.
ACCEPT AMOUNT.
ACCEPT RATE.
*> Read PAYMENT here
MOVE AMOUNT TO BALANCE.
*> Perform PAY-MONTH until BALANCE is zero
STOP RUN.
PAY-MONTH.
*> One month: interest, payment, one line
CALC-INTEREST.
COMPUTE INTEREST ROUNDED =
BALANCE * RATE / 1200.