我正在编写一个简单的COBOL程序来读取数据并根据学分时数计算学费。我的程序是完整的,除了一个我不明白的错误。在CALC例程的最后一行,我尝试编写TUITION变量,我得到错误:“不是记录名称”。我还在学习COBOL程序的基本结构和设置,所以我知道这是我忘记的一些小错误。
代码:
IDENTIFICATION DIVISION.
PROGRAM-ID. prg1-lankford.
AUTHOR. Lankford.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT DISK-FILE ASSIGN TO 'prg1.dat'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT PRINT-FILE ASSIGN TO 'prg1-lankford.rpt'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD DISK-FILE
RECORD CONTAINS 80 CHARACTERS.
01 DISK-REC.
05 STUDENT-NAME-INPUT PIC X(20).
05 NUM-CREDITS-INPUT PIC 9(2).
05 PIC X(58).
FD PRINT-FILE
RECORD CONTAINS 66 CHARACTERS.
01 PRINT-REC.
05 STUDENT-NAME-OUTPUT PIC X(20).
05 PIC X(20).
05 NUM-CREDITS-OUTPUT PIC 9(2).
05 PIC X(20).
05 TUITION PIC 9(4).
WORKING-STORAGE SECTION.
01 MORE-RECORDS PIC X VALUE 'Y'.
01 FULL-TIME-TUITION PIC 9(4) VALUE 6300.
01 PER-CREDIT PIC 9(3) VALUE 525.
PROCEDURE DIVISION.
100-MAIN-MODULE.
OPEN INPUT DISK-FILE
OUTPUT PRINT-FILE
PERFORM UNTIL MORE-RECORDS = 'N'
READ DISK-FILE
AT END
MOVE 'N' TO MORE-RECORDS
NOT AT END
PERFORM 200-CALC-RTN
END-READ
END-PERFORM
CLOSE DISK-FILE
PRINT-FILE
STOP RUN.
200-CALC-RTN.
MOVE STUDENT-NAME-INPUT TO STUDENT-NAME-OUTPUT
MOVE NUM-CREDITS-INPUT TO NUM-CREDITS-OUTPUT
IF NUM-CREDITS-INPUT < 12 THEN
MULTIPLY NUM-CREDITS-INPUT BY PER-CREDIT
GIVING TUITION
ELSE
MOVE FULL-TIME-TUITION TO TUITION
WRITE TUITION.
答案 0 :(得分:3)
尝试
Write PRINT-REC
你只能写完整记录而不是记录的一部分。
写之前 缺少 end-if ,请尝试:
200-CALC-RTN.
MOVE STUDENT-NAME-INPUT TO STUDENT-NAME-OUTPUT
MOVE NUM-CREDITS-INPUT TO NUM-CREDITS-OUTPUT
IF NUM-CREDITS-INPUT < 12 THEN
MULTIPLY NUM-CREDITS-INPUT BY PER-CREDIT
GIVING TUITION
ELSE
MOVE FULL-TIME-TUITION TO TUITION
end-if
WRITE PRINT-REC.