我正在慢慢学习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
答案 0 :(得分:2)
将程序放入在线编译器(代码和结果here)后,看到两个问题:
WS-CIRCUMFRENCE
-> WS-CIRCUMFENCE
由于您似乎不使用自由格式,但是基于列的选项我已经从该项目中删除了该选项(-free
,修复了上面指定的问题并添加了最小缩进,结果:works like a charm
我考虑了可能的问题,但我唯一想到的是另外一个DECIMAL-POINT IS COMMA
规范-但这引起了error: invalid level number '14159'
或缩进(这很可能会看到);您可能要重新检查您是否不按TAB进行缩进(它们的实际大小可能在您的编辑器显示的内容和编译器使用的内容之间有所不同(默认情况下,大多数编译器使用8个空格)
答案 1 :(得分:2)
除了上述建议外,我还将添加更改
COMPUTE WS-RADIUS = WS-PI * WS-RADIUS * WS-RADIUS.
到
COMPUTE WS-AREA = WS-PI * WS-RADIUS * WS-RADIUS.
否则您将始终为区域打印0