私は COBOL でのプログラミングの初心者であり、おそらく些細なことで苦労しています。ユーザーが入力した最小値と最大値を見つけたいと思っています。ユーザーが 0 をヒットすると、最大、最小、および平均が表示されます。平均は簡単ですが、最小値と最大値には疑問がありました。これがJAVAまたは別の言語である場合、MAX INT値を比較していくつかのシナリオを実行します。残念ながら、COBOL の High-Value と Low-Value は整数値ではありませんか???? そこで、ユーザーのエントリをテーブルに入れ、組み込み関数を使用して必要なことを行うことにしました。ただし、次のように計算しようとするとすぐに:
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.