Need help in Exercise 1 of COBOL Track

Hello,
I can´t pass Tests in Exercise 1 of COBOL Track.
Tests Failed messages refer to line numbers, code and variables that are not present or used in my code.

Tests Failed messages:
test.cob:155: error: ‘WS-YEAR’ is not defined
153 | TO UT-TEST-CASE-NAME…
154 | PERFORM UT-INITIALIZE-MOCK-COUNT…
155 > MOVE 2015 TO WS-YEAR…
156 | PERFORM LEAP…
157 | ADD 1 TO UT-TEST-CASE-COUNT…
test.cob:160: error: ‘WS-RESULT’ is not defined
158 | SET UT-NORMAL-COMPARE TO TRUE…
159 | SET UT-ALPHANUMERIC-COMPARE TO TRUE…
160 > MOVE WS-RESULT TO UT-ACTUAL…
161 | MOVE 0…
162 | TO UT-EXPECTED…
test.cob:156: error: ‘LEAP’ is not defined
154 | PERFORM UT-INITIALIZE-MOCK-COUNT…
155 | MOVE 2015 TO WS-YEAR…
156 > PERFORM LEAP…
157 | ADD 1 TO UT-TEST-CASE-COUNT…
158 | SET UT-NORMAL-COMPARE TO TRUE…

My code:

   *>>source format is free
   *> *************************************************************
   *> Author:    Geiza
   *> Date:      Oct-2025
   *> Purpose:   Determine if an year is leap
   *> *************************************************************
   IDENTIFICATION DIVISION.
   PROGRAM-ID. Verify-Leap-Year.
   ENVIRONMENT DIVISION.
   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 YEAR-IN PIC 9(004) VALUE ZERO.
   01 LEAP-RESULT PIC 9(001) VALUE ZERO.
   01 YEAR-IS-LEAP. 
     03 FILLER PIC X(20) VALUE "YEAR IS LEAP".
   01 YEAR-IS-NOT-LEAP. 
     03 FILLER PIC X(20) VALUE "YEAR IS NOT LEAP".
   PROCEDURE DIVISION.
   MAIN-ROUTINE.
      ACCEPT YEAR-IN.
      PERFORM CHECK-LEAP.		
      IF LEAP-RESULT EQUALS 0
         DISPLAY YEAR-IS-LEAP
      ELSE
         DISPLAY YEAR-IS-NOT-LEAP
      END-IF.
   STOP RUN.	 
   CHECK-LEAP.
   *>Solution
      IF FUNCTION MOD(YEAR-IN;4) = 0
         IF FUNCTION MOD(YEAR-IN;100) = 0	
            IF FUNCTION MOD(YEAR-IN;400) = 0	
            *>Year is leap (divisible by 400)
               MOVE 1 TO LEAP-RESULT
            ELSE
            *>Year is not leap (divisible by 100, 
            *>but not divisible by 400)
               MOVE 0 TO LEAP-RESULT
         ELSE
         *>Year is leap (divisible by 4, but not divisible by 100)
            MOVE 1 TO LEAP-RESULT
      ELSE
      *>Year is not leap (not divisible by 4)
         MOVE 0 TO LEAP-RESULT
      END-IF.

Thanks a lot for any help you can give me.

Have you looked at the tests and what they expect your program to do?

TestCase "year not divisible by 4 in common year"
	MOVE 2015 TO WS-YEAR
	PERFORM LEAP
	EXPECT WS-RESULT = 0

@geizaoliveira Maybe you want to read why STOP RUN is not allowed in our COBOL track? I think this has not yet found its way into the testing docs of the track…

@geizaoliveira

Welcome to the Cobol track. Your solution has a couple of problems.

  1. Exercism uses a program called cobol-check for testing your solution. It essentially embeds your solution into a program that runs particular paragraphs in your solution (which is the leap paragraph in the leap exercise). In order for cobol-check to do the job correctly, your solution is written in the fixed-format. Please fix the format.
  2. Your solution has no paragraph named leap. When you got the original source file, it must have looked like:
       IDENTIFICATION DIVISION.
       PROGRAM-ID. LEAP.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       PROCEDURE DIVISION.
       LEAP.
      * Enter solution here
         CONTINUE.
       LEAP-EXIT.
         EXIT.
    
    You need to follow the instruction given there.
  3. The file tst/leap/leap.cut describes what tests are going to be performed. It is written in a domain-specific languange that looks like a cobol code. You see in the file that the test substitute various values to WS-YEAR and expects certain values in WS-RESULT. This means that your solution must declare the two variables and use them suitably.

I made the minimal change to your solution to do the things described above.

      *> *************************************************************
      *> Author:    Geiza
      *> Date:      Oct-2025
      *> Purpose:   Determine if an year is leap
      *> *************************************************************
       IDENTIFICATION DIVISION.
       PROGRAM-ID. Verify-Leap-Year.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-YEAR PIC 9(4).
       01 WS-RESULT PIC 9.
       01 YEAR-IN PIC 9(004) VALUE ZERO.
       01 LEAP-RESULT PIC 9(001) VALUE ZERO.
       01 YEAR-IS-LEAP. 
         03 FILLER PIC X(20) VALUE "YEAR IS LEAP".
       01 YEAR-IS-NOT-LEAP. 
       03 FILLER PIC X(20) VALUE "YEAR IS NOT LEAP".
       PROCEDURE DIVISION.
       MAIN-ROUTINE.
           ACCEPT YEAR-IN.
           PERFORM CHECK-LEAP.		
           IF LEAP-RESULT EQUALS 0
              DISPLAY YEAR-IS-LEAP
           ELSE
              DISPLAY YEAR-IS-NOT-LEAP
           END-IF.
           STOP RUN.	 
       LEAP.
           move WS-YEAR TO YEAR-IN
           PERFORM CHECK-LEAP.
           MOVE LEAP-RESULT TO WS-RESULT.
       CHECK-LEAP.
      *>Solution
          MOVE 0 TO LEAP-RESULT
          IF FUNCTION MOD(YEAR-IN;4) = 0
             IF FUNCTION MOD(YEAR-IN;100) = 0	
                IF FUNCTION MOD(YEAR-IN;400) = 0	
      *>Year is leap (divisible by 400)
                   MOVE 1 TO LEAP-RESULT
                ELSE
      *>Year is not leap (divisible by 100, 
      *>but not divisible by 400)
                   MOVE 0 TO LEAP-RESULT
                ELSE
      *>Year is leap (divisible by 4, but not divisible by 100)
                   MOVE 1 TO LEAP-RESULT
                ELSE
      *>Year is not leap (not divisible by 4)
                   MOVE 0 TO LEAP-RESULT
                END-IF.

This code goes through all tests without syntax errors and passes all tests. But I hope that you will rewrite it in a better way. Please remember that you can always request a tutoring session to get help.

1 Like

Thanks a lot for such a helpfull and well explained answer. I’m really grateful because I’ve learned a lot of about working in Exercism that I didn’t know before.

1 Like

You are welcome. Enjoy the ride through the COBOL adventure!

2 Likes

PROCEDURE DIVISION.
INICIO.
DISPLAY “INGRESE ANIO: "
ACCEPT WS-ANIO
STRING WS-ANIO “0229” DELIMITED BY SIZE
INTO WS-FECHA
COMPUTE WS-RESULT = FUNCTION TEST-DATE-YYYYMMDD (WS-FECHA)
IF WS-RESULT = 0
DISPLAY WS-ANIO " BISIESTO”
ELSE
DISPLAY WS-ANIO " NO BISIESTO"
END-IF
STOP RUN.

no help .

another way to search