首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >COBOL程序中存在语法错误,如果

COBOL程序中存在语法错误,如果
EN

Stack Overflow用户
提问于 2016-02-08 10:51:36
回答 1查看 908关注 0票数 0

我正在用COBOL编写代码,在添加了下面列出的if语句后,我一直得到“在段落‘000-main’中: Error:语法错误,意外的IF”。

代码语言:javascript
复制
   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语句之前,一切都编译得很好。

代码语言:javascript
复制
          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
EN

回答 1

Stack Overflow用户

发布于 2016-02-09 02:50:07

我没有编译你的代码。

您缺少IF语句的END-IF。你还应该加上一个"STOP RUN“。在你的程序中。例如..。

代码语言:javascript
复制
 perform until month-counter = num-months
      add 1 to month-counter

      Divide month-counter By months-in-year Giving Q Remainder R
      if ( (num-months> months-in-year) & (R=0))
         Add additional-value to balance-month
      end-if ******* <- YOU NEED THIS
      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
  STOP RUN. *** <- THIS WOULD BE NICE AS WELL.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35261731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档