
COBOL I
Interactive
Programming
For this application, we will develop an interactive program for finding the monthly payment for a house mortgage.
You will have ACCEPT and DISPLAY statements for the following:
price of the house (pic 9(6))
down payment on the house (pic 9(6))
number of years to be financed (pic 99)
annual interest rate (pic V9999)
You will then calculate the monthly payment on the house and display that value (with an appropriate label).
The formula is:

Note - this formula uses the exponentiation operation - illustrated by the caret ^ here - but uses the ** in COBOL - see pages 267-270.
Your processing will be similar to this:
3000-PROCESSING. PERFORM 3100-GET-VALUES. PERFORM 3200-CALCULATION. PERFORM 3300-DISPLAY-VALUES. PERFORM 3400-CONTINUE-ON.
3100-GET-VALUES. DISPLAY "PLEASE ENTER THE PRICE OF THE HOUSE". ACCEPT HOUSE-PRICE. DISPLAY " ". DISPLAY "PLEASE ENTER THE DOWN PAYMENT". ACCEPT DOWN-PAYMENT. DISPLAY " ". DISPLAY "PLEASE ENTER THE YEARS TO BE FINANCED". ACCEPT YEARS. DISPLAY " ". DISPLAY "PLEASE ENTER THE INTEREST RATE (MUST INCLUDE A DECIMAL POINT)". ACCEPT RATE.
3200-CALCULATION.
COMPUTE PRINCIPLE = HOUSE-PRICE - DOWN-PAYMENT.
COMPUTE MRATE = RATE / 12. <-- if you use MRATE - define it as PIC V99999999.
(I'm thinking of MRATE as monthly rate - thus the division by 12)
COMPUTE PAYMENT = (insert formula here)
3300-DISPLAY-VALUES. (insert coding to display payment amount - see additional comments below . . )
3400-CONTINUE-ON. DISPLAY "DO YOU WANT TO CONTINUE WITH ANOTHER VALUE (Y/N)?". ACCEPT GO-ON-INDICATOR.
In your main module you will have:
PERFORM 3000-PROCESSING UNTIL GO-ON-INDICATOR = "N".
Try processing with these values:
house price: 120000
down payment: 20000
years to finance: 30
interest rate (must include decimal): .0875
(the payment should be about $786.70)
house price: 85000
down payment: 10000
years to finance: 30
interest rate (must include decimal): .0925
====================
Additional comments:
You can insert a SCREEN SECTION in the DATA DIVISION - after the Working-Storage
Section.
SCREEN SECTION.
01 BLANK-SCREEN.
05 BLANK SCREEN.
Add the following when you want a new screen:
DISPLAY BLANK-SCREEN.
Define PAYMENT-OUT PIC $$$,$$9.99. in Working-Storage
Then:
MOVE PAYMENT TO PAYMENT-OUT
DISPLAY PAYMENT-OUT.