我在编译时运行了两个错误,我无法弄清楚。“在段落‘CALC-AVG’:”和“calcavg.cob:30:错误:'INTS'需要一个下标”我无法计算这些.下面是程序的代码
IDENTIFICATION DIVISION.
PROGRAM-ID. ASSIGNMENT4.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NUM-OF-INTS PIC 99.
01 INT-ARRAY.
05 INTS OCCURS 15 TIMES PIC 999.
01 TOTAL PIC 9(5)V99.
01 AVG PIC 9(3)V99.
01 COUNTER PIC 99.
PROCEDURE DIVISION.
MAIN-LOGIC.
DISPLAY "Enter number of integers to average (2-15): ".
ACCEPT NUM-OF-INTS.
PERFORM ACCEPT-INTS
PERFORM CALC-AVG
DISPLAY "Average: " AVG DISPLAY "ZZZ.99".
STOP RUN.
ACCEPT-INTS.
DISPLAY "Enter integers to average: ".
PERFORM VARYING COUNTER FROM 1 BY 1 UNTIL COUNTER>NUM-OF-INTS
DISPLAY "Integer " COUNTER ": "
ACCEPT INTS(COUNTER)
END-PERFORM.
CALC-AVG.
COMPUTE TOTAL = FUNCTION SUM(INTS(1:NUM-OF-INTS))
COMPUTE AVG = TOTAL / NUM-OF-INTS.
EXIT.
1条答案
按热度按时间nue99wik1#
(1:NUM-OF-INTS)
不是下标,此格式用于引用修改;也就是说,从USAGE DISPLAY
数据项中选择一个子字符串,您似乎将它用作整个表的数组切片。请使用以下命令:
DEPENDING ON
限制了要与ALL
下标相加的项目数。ALL
下标与SUM
将把这么多数字相加在一起。然后将结果值移动到TOTAL
。要解决无法识别
ALL
的问题,请使用以下语句替换COMPUTE
语句: