我是COBOL编程的新手,我很难做到可能应该是微不足道的事情。我想找到用户输入的最小值和最大值。当用户点击0时,应显示最大值,最小值和平均值。 avg很容易,但最小和最大让我感到疑惑。如果这是JAVA或其他lang我只是做一些比较MAX INT值的情况。不幸的是,COBOL中的高值和低值不是整数值????所以我决定将用户的条目放在一个表中,然后使用内部函数来做我需要的。但是,只要我尝试这样计算:
compute Min-Result = Function Min (Num-Field(ALL))
我收到一条错误消息,“语法错误,意外全部。”关于该做什么以及为什么我得到这个错误,我完全感到困惑。我正在使用OpenCOBOL 1.1 Mingw。这是我的完整代码。任何帮助将不胜感激。什么都没有。我也确保没有超过72行。
identification division.
program-id. lab1a.
* no envionrment division since there are no files needed, etc.
data division.
working-storage section.
* declaring proper variables to store integer values
01 Max-Result PIC S9(5).
01 Min-Result PIC S9(5).
01 Count-Val PIC 9 Value 0.
01 Running-Tot PIC S9(10)v99.
01 First-Zero PIC 9 Value 1.
01 Final-Format-Avg PIC ZZZZZ9.9999.
01 Avg-Ent PIC S9(5)v9999.
01 Calc-Table.
03 Table-Record Occurs 1 to 500 times
depending on Entered-Num.
05 Num-Field PIC S9(5).
01 Entered-Num PIC S9(5).
procedure division.
000-Main.
perform with test after until Entered-Num = 0
display "Enter a 4-digit number (0 to stop): "
with no advancing
accept Entered-Num
add 1 to Count-Val
add Entered-Num to Running-Tot
display Running-Tot
display Count-Val
move Entered-Num to Num-Field(Count-Val)
* this way every time the user enters a non zero number it will be re-assigned
* to the variable Ending-Num. If they enter zero the if condition is skipped, the
* loop condition is tested at the top and is ended.
end-perform.
subtract 1 from Count-Val
display Count-Val
display " "
display " "
*WATCH FOR TRUNCATION ERROR.....
Divide Running-Tot By Count-Val Giving Avg-Ent
move Avg-Ent to Final-Format-Avg
*******WHY DOES THIS NOT WORK???????***********************
compute Min-Result = Function Min (Num-Field(ALL))
compute Max-Result = Function Max (Num-Field(ALL))
if First-Zero = 0
display "The first number you entered was zero.
& Next time enter a different one."
else
display "The lowest value entered: " Min-Result
display "The highest value entered: " Max-Result
display "The average value entered: "
Final-Format-Avg
end-if
stop run.
答案 0 :(得分:3)
OpenCOBOL内部函数目前不支持ALL,这是一个可以实现的功能。
答案 1 :(得分:2)
根据字段的不同,您有“输入的数字”。使用该函数时输入的数值为零。它应该是Count-Val。
这不是问题,但是你问了。
看一下2009年OpenCobol程序员的Guid,我发现没有确认支持ALL。
保持“最低值”和“最高值”会更简单/更快,并根据输入的数字与/替换进行比较。