关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。
想改进这个问题?将问题更新为 on-topic对于堆栈溢出。
6年前关闭。
Improve this question
我在 COBOL 中编码,在添加下面列出的 if 语句后,我不断得到
"
在“000-main”段中:
错误:语法错误,意外的 IF"
Identification Division.
Program-ID. Lab2.
*This program will generate a statement for a single investment
*that compounds interest monthly.
* It will prompt use for 3 inputs, calculate total interest
* earned, final balance, & entire account balance schedule.
* It will then display all output to the console.
Environment Division.
Data Division.
Working-Storage Section.
01 invest-amt pic S9(9)V99.
01 invest-error-msg pic x(40) value "Investment "
& "Amount must be positive".
01 int-rate pic S9(2)V99.
01 int-rate-error-msg pic x(40) value "Annual Interest "
& "Rate must be positive".
01 int-rate-final pic 9V99999.
01 num-months pic S9(3).
01 num-months-error-msg pic x(40) value "Number of Months "
& "must be positive".
01 multiply-rate pic 9V99999.
01 blank-line pic x value " ".
01 month-counter pic 99 value 1.
01 balance-month pic 9(9)V99.
01 interest-month pic 9(9)V99.
01 total-interest pic 9(9)V99.
01 final-balance pic 9(9)V99.
01 additional-value pic S9(9)V99.
01 add-value-error-msg pic x(40) value "Additional Value "
& "must be positive".
01 Q pic 9(3).
01 R pic 9(3).
01 months-in-year pic 9(2) Value 12.
Procedure Division.
000-main.
perform 100-initialize
perform until invest-amt >=0
display invest-error-msg
perform 200-input
end-perform
perform 210-input-rate
perform until int-rate >=0
display int-rate-error-msg
perform 210-input-rate
end-perform
perform 220-input-month
perform until num-months >=0
display num-months-error-msg
perform 220-input-month
end-perform
perform 230-input-additional-value
perform until additional-value >=0
display add-value-error-msg
perform 230-input-additional-value
end-perform
perform 300-print-words
perform 400-process-interest
perform 310-print-values
display blank-line
perform until month-counter = num-months
add 1 to month-counter
Divide month-counter By months-in-year Giving Q Remainder R
在我添加下面的 if 语句之前,一切都编译得很好。
if ( (num-months> months-in-year) & (R=0))
Add additional-value to balance-month
multiply month-counter by months-in-year
add interest-month to balance-month rounded
perform 400-process-interest
perform 310-print-values
display blank-line
end-perform
最佳答案
我的编译器提示缺少 end-if
并且不喜欢&。我以明显的方式修复了 & 问题。
插入 end-if
在 Add additional-value to balance-month
之后似乎产生了一个干净的编译。自然是最后的end-perform
需要一个句号
最终执行。
我怀疑您的编译器正在生成该消息,因为您的 if
语句格式不正确。
关于if-statement - COBOL 程序中的语法错误,如果发生意外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35261731/