在 cobol 程序中得到不需要的输出
getting unwanted output in cobol program
好的,这是我第一次 post 在这里,这是我被卡住的部分。我正在获取一个输入文件并输出一个错误列表,我必须做的部分之一是一个学区,它是一个字符串 3。在程序部门我有
执行 B 段
执行C段
B 段是发现所有其他错误的地方,因为它们实际上只需要 1 个 if 语句。
C段是学区部分。它检查 School District 是否不是有效格式。仅在以下情况下有效:
- 3个字符都是空格;或
- 前两个字符是数字,并且:
- 如果相同,则第3个字符不能为数字;或
- 如果不相同,则其中一个必须是奇数,另一个是偶数。
在工作存储部分,我将学区列为
05 District.
10 DistrictA PIC 9.
10 DistrictB PIC 9.
10 DistrictC PIC 9.
然后在C段我有
if DistrictA <> " " and DistrictB <> " "
and DistrictC <> " "
write ot-records from
"School District is not valid:"
add 1 to Counter
Exit Paragraph
End-if.
if DistrictA is not numeric or DistrictB is not numeric
write ot-records from
"School District is not valid:"
add 1 to Counter
Exit Paragraph
End-if.
if DistrictA = DistrictB
if DistrictC is numeric
write ot-records from
"School District is not valid:"
add 1 to Counter
Exit Paragraph
End-if
Else if DistrictA <> DistrictB and
(DistrictA + DistrictA) / 2 = 0 and
(DistrictB + DistrictB) / 2 <> 0
write ot-records from
"School District is not valid:"
add 1 to Counter
Exit Paragraph.
从输出中可以看出,每个文件的“学区无效”。所以最后的计数比它应该的要大。
您的代码中有逻辑流程。在“三个都不是空格”的情况下,您直接在第一个 IF
中退出,在“三个都是空格”的情况下,您总是在第二个 IF
中退出(因为前两个空格 -> 从不数字).
您可能希望合并多个条目或通过反转逻辑使代码更简单 -> 仅在区域有效且最后位置有错误处理(这在任何情况下都很有用)时才退出段落因为您只有一次相同的代码,所以在三个或其他更难发现错误的其中一个中没有拼写错误的选项,并且以后更容易调整)。
根据任务,您可能希望使用 88 级项目来检查 some/all 条件,这样它们就直接附加到变量。
好的,这是我第一次 post 在这里,这是我被卡住的部分。我正在获取一个输入文件并输出一个错误列表,我必须做的部分之一是一个学区,它是一个字符串 3。在程序部门我有 执行 B 段 执行C段
B 段是发现所有其他错误的地方,因为它们实际上只需要 1 个 if 语句。
C段是学区部分。它检查 School District 是否不是有效格式。仅在以下情况下有效:
- 3个字符都是空格;或
- 前两个字符是数字,并且:
- 如果相同,则第3个字符不能为数字;或
- 如果不相同,则其中一个必须是奇数,另一个是偶数。
在工作存储部分,我将学区列为
05 District.
10 DistrictA PIC 9.
10 DistrictB PIC 9.
10 DistrictC PIC 9.
然后在C段我有
if DistrictA <> " " and DistrictB <> " "
and DistrictC <> " "
write ot-records from
"School District is not valid:"
add 1 to Counter
Exit Paragraph
End-if.
if DistrictA is not numeric or DistrictB is not numeric
write ot-records from
"School District is not valid:"
add 1 to Counter
Exit Paragraph
End-if.
if DistrictA = DistrictB
if DistrictC is numeric
write ot-records from
"School District is not valid:"
add 1 to Counter
Exit Paragraph
End-if
Else if DistrictA <> DistrictB and
(DistrictA + DistrictA) / 2 = 0 and
(DistrictB + DistrictB) / 2 <> 0
write ot-records from
"School District is not valid:"
add 1 to Counter
Exit Paragraph.
从输出中可以看出,每个文件的“学区无效”。所以最后的计数比它应该的要大。
您的代码中有逻辑流程。在“三个都不是空格”的情况下,您直接在第一个 IF
中退出,在“三个都是空格”的情况下,您总是在第二个 IF
中退出(因为前两个空格 -> 从不数字).
您可能希望合并多个条目或通过反转逻辑使代码更简单 -> 仅在区域有效且最后位置有错误处理(这在任何情况下都很有用)时才退出段落因为您只有一次相同的代码,所以在三个或其他更难发现错误的其中一个中没有拼写错误的选项,并且以后更容易调整)。
根据任务,您可能希望使用 88 级项目来检查 some/all 条件,这样它们就直接附加到变量。