KD Fer
KD Fer

Reputation: 101

Getting errors and not sure why still learning COBOL

I am looking to nest two loops together. I want to find the largest integer that is divisible from 1 to 20 evenly. My code for the program is as follows:

IDENTIFICATION DIVISION.
PROGRAM-ID. EULER3.
DATA DIVISION.
WORKING-STORAGE SECTION.
    01 startNum PIC 9(10) VALUE 380.
    01 counter PIC 9(2).
    01 check PIC 9(1) VALUE 0.
    01 finalVal PIC 9(10)
PROCEDURE DIVISION.
MAIN-PROCEDURE. 

PERFORM whileLoop UNTIL check = 1.
DISPLAY "Largest number divisible by 19 thru 20 " startNum. 
STOP RUN.

whileLoop.
    SET counter TO 11.
    DISPLAY counter.
    PERFORM forLoop UNTIL counter = 20

forLoop.
    IF FUNCTION MOD(startNum, counter) = 0
        IF counter = 19
            SET finalVal TO startNum.
            ADD 1 TO check.
    ELSE
        ADD 20 TO startNum

    ADD 1 TO counter.
    END-IF. 

And the Console is:

 jdoodle.cobc:30: warning: line not terminated by a newline
 jdoodle.cobc:9: error: syntax error, unexpected PROCEDURE, expecting EXTERNAL or EXTERNAL-FORM or GLOBAL or IDENTIFIED
 jdoodle.cobc:10: error: PROCEDURE DIVISION header missing
 jdoodle.cobc:10: error: syntax error, unexpected Identifier
 jdoodle.cobc: in paragraph 'whileLoop':
 jdoodle.cobc:21: error: 'forLoop' is not defined
 jdoodle.cobc:19: error: invalid expression
 jdoodle.cobc:26: error: syntax error, unexpected ELSE
 jdoodle.cobc:30: error: syntax error, unexpected END-IF
 jdoodle.cobc:19: error: 'forLoop' is not defined

I am not sure why it is saying I don't have a procedure division. I have written my program in Python and used this method, hence why I have named my areas forLoop and whileLoop.

Upvotes: 2

Views: 717

Answers (1)

Gilbert Le Blanc
Gilbert Le Blanc

Reputation: 51445

I may have missed some other syntax errors.

01 finalVal PIC 9(10)  add a final period.  

SET finalVal TO startNum.   remove the period.

ADD 1 TO check.   remove the period.

ADD 20 TO startNum   add an END-IF

ADD 1 TO counter.   remove the period.

Upvotes: 2

Related Questions