收到错误不太清楚为什么这是我的第一个 cobol 程序

Getting errors not quite sure why this is my first cobol program

我正在慢慢学习 COBOL 并正在做一些挑战以变得更好,但我遇到了一个奇怪的问题,我似乎无法追踪,我想看看是否有其他人可以提供帮助

我仔细检查了 A 区和 B 区的正确编号

IDENTIFICATION DIVISION.
    PROGRAM-ID. CIRCLES.

    ENVIRONMENT DIVISION.
    CONFIGURATION SECTION.
    SOURCE-COMPUTER.
    OBJECT-COMPUTER.

    INPUT-OUTPUT SECTION.
    FILE-CONTROL.


    DATA DIVISION.
    FILE SECTION.

    WORKING-STORAGE SECTION.
    01  WS-CONSTANTS.
        05  WS-PI              PIC 9V99999 VALUE 3.14159.
    01   WS-CIRCLE.
        05 WS-AREA              PIC 999V99 VALUE ZEROES.
        05 WS-RADIUS            PIC 9999V99 VALUE ZEROES.
        05 WS-CIRCUMFERENCE     PIC 99999V99 VALUE ZEROES.
    01   WS-DISPLAY-VALUES.
        05 WS-DISPLAY-AREA                     PIC ZZ99.99.
        05 WS-DISPLAY-CIRCUMFERENCE  PIC ZZ99.99.



    PROCEDURE DIVISION.

    0100-PROCESS-RECORDS.

        DISPLAY "Please enter radius of circle: ".
        ACCEPT WS-RADIUS.
        COMPUTE WS-CIRCUMFRENCE = 2 * WS-PI * WS-RADIUS.
        MOVE WS-CIRCUMFRENCE TO WS-DISPLAY-CIRCUMFRENCE.
        DISPLAY "Circle Circumfrence is: ", WS-DISPLAY-CIRCUMFRENCE.
        COMPUTE WS-RADIUS = WS-PI * WS-RADIUS * WS-RADIUS.
        MOVE WS-AREA TO WS-DISPLAY-AREA.
        DISPLAY "Circle area is:  ", WS-DISPLAY-AREA

        STOP RUN

编译器消息:

Circles.cbl:28: error: PROCEDURE DIVISION header missing
Circles.cbl:28: error: syntax error, unexpected level-number
Circles.cbl:29: error: unknown statement '05'
Circles.cbl:30: error: unknown statement '05'
Circles.cbl:34: error: syntax error, unexpected PROCEDURE
Circles.cbl: in paragraph '0100-PROCESS-RECORDS':
Circles.cbl:40: error: 'WS-RADIUS' is not defined
Circles.cbl:41: error: 'WS-CIRCUMFRENCE' is not defined
Circles.cbl:41: error: 'WS-PI' is not defined
Circles.cbl:41: error: 'WS-RADIUS' is not defined
Circles.cbl:42: error: 'WS-CIRCUMFRENCE' is not defined
Circles.cbl:42: error: 'WS-DISPLAY-CIRCUMFRENCE' is not defined
Circles.cbl:43: error: 'WS-DISPLAY-CIRCUM' is not defined
Circles.cbl:44: error: 'WS-RADIUS' is not defined
Circles.cbl:44: error: 'WS-PI' is not defined
Circles.cbl:44: error: 'WS-RADIUS' is not defined
Circles.cbl:44: error: 'WS-RADIUS' is not defined
Circles.cbl:45: error: 'WS-AREA' is not defined
Circles.cbl:45: error: 'WS-DISPLAY-AREA' is not defined
Circles.cbl:46: error: 'WS-DISPLAY-AREA' is not defined

将程序放入在线编译器(代码+结果 here)后发现两个问题:

  • 打字错误:WS-CIRCUMFRENCE -> WS-CIRCUMFENCE
  • 末尾缺少分隔符

由于您似乎不使用自由格式而是基于列的格式,我已经从该项目中删除了该选项(-free,修复了上述问题并添加了最小缩进,结果:works like a charm.

我考虑过可能的问题,但我唯一能想到的是 DECIMAL-POINT IS COMMA 的附加规范 - 但它会引发 error: invalid level number '14159',或错误的缩进(这很可能会被看到);您 可能 想重新检查您是否没有使用 TAB 进行缩进(它们的实际大小可能在您的编辑器显示的内容和编译器使用的内容之间有所不同 [大多数编译器使用 8 个空格的大小默认情况下)。

除了上述建议外,我还要添加更改

COMPUTE WS-RADIUS = WS-PI * WS-RADIUS * WS-RADIUS.

COMPUTE WS-AREA = WS-PI * WS-RADIUS * WS-RADIUS.

否则你将始终打印出面积为 0