重新启动程序COBOL(再次…)

我已经做了这个答案,但是我没有令人满意的答案,并且我也更新了代码 我有一个小问题,我用cobol写了一个计算器,但我不是那么熟练,我在这里给你代码

它基本上会打印“计算器”,并提供15种选择:

       IF INPUT1 = 15
            DISPLAY "OK, GOOD JOB :)"
            STOP RUN
        END-IF.

       IF INPUT1 = 1
       DISPLAY "FIRST NUMBER"
       ACCEPT A
       DISPLAY "SECOND NUMBER"
       ACCEPT B
       COMPUTE C= A + B
               DISPLAY "Computing"
               DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY A"+" B " RESULTS..."
               DISPLAY C
       ELSE
           IF INPUT1 = 2
               DISPLAY "FIRST NUMBER"
               ACCEPT A
               DISPLAY "SECOND NUMBER"
               ACCEPT B
               DISPLAY "Computing"
               DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY A "-" B " RESULTS..."
               COMPUTE C= A - B
               DISPLAY C
                   ELSE
                       IF INPUT1 = 3
                   DISPLAY "FIRST NUMBER"
                   ACCEPT A
                   DISPLAY "SECOND NUMBER"
                   ACCEPT B
                   COMPUTE C= A * B
                          DISPLAY "Computing"
                          DISPLAY "Computing."
                          DISPLAY "Computing.."
                          DISPLAY "Computing..."
                          DISPLAY "Computing...."
                          DISPLAY "Computing....."
                          DISPLAY "Computing......"
                          DISPLAY A "x" B " RESULTS..."
                          DISPLAY C
                       ELSE
                           IF INPUT1 = 4
                           DISPLAY "FIRST NUMBER"
                           ACCEPT A
                           DISPLAY "SECOND NUMBER"
                           ACCEPT B
                           COMPUTE C= A / B
                          DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY A ":" B " RESULTS..."
                           DISPLAY C
                           ELSE
                           IF INPUT1 = 5
                           DISPLAY "NUMERO TO SQUARE"
                           ACCEPT A
                           COMPUTE C= A * A
                          DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY A"^2" " RESULTS..."
                           DISPLAY C
                           ELSE
                               IF INPUT1 = 6
                           DISPLAY "NUMBER TO CUBE"
                           ACCEPT A
                           COMPUTE C= A * A * A
                          DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY A"^3" " RESULTS..."
                           DISPLAY C
                           ELSE
                               IF INPUT1 = 7
                           DISPLAY "SQUARE ROOT OF..."
                           ACCEPT A
                           COMPUTE C= FUNCTION SQRT(A)
                           END-COMPUTE
                          DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY "/"A " RESULTS..."
               DISPLAY C
               ELSE
               IF INPUT1 = 8
                           DISPLAY "CUBE ROOT OF..."
                           ACCEPT A
                           COMPUTE C= A ** 0.33
                           END-COMPUTE
                          DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "3/"A " RESULTS..."
                           DISPLAY C
                           ELSE
                               IF INPUT1 = 9
                           DISPLAY "SIN OF..."
                           ACCEPT A
                         COMPUTE C= FUNCTION SIN(A * 3.14159 / 180)
                           END-COMPUTE
                          DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY "SIN OF " A " RESULTS..."
                           DISPLAY C " DEGREES"
                               ELSE
                                   IF INPUT1 = 10
                           DISPLAY "COS OF..."
                           ACCEPT A
                          COMPUTE C= FUNCTION COS(A * 3.14159 / 180)
                           END-COMPUTE
                          DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY "COS OF " A " RESULTS..."
                           DISPLAY C" DEGREES"
                           ELSE
                               IF INPUT1 = 11
                           DISPLAY "TAN OF..."
                           ACCEPT A
                          COMPUTE C= FUNCTION TAN(A * 3.14159 / 180)
                           END-COMPUTE
                          DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY "A " "FA..."
               DISPLAY "TAN OF " A " RESULTS..."
               DISPLAY C " DEGREES"
               ELSE
               IF INPUT1 = 12
                           DISPLAY "SIN ^-1 OF..."
                           ACCEPT A
                         COMPUTE C= FUNCTION ASIN(A * 3.14159 / 180)
                           END-COMPUTE
                           COMPUTE C= (C / 3.14159 * 180)
                          DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY "SIN^-1 OF " A " RESULTS..."
                           DISPLAY C " DEGREES"
                               ELSE
                                   IF INPUT1 = 13
                           DISPLAY "COS ^-1 OF..."
                           ACCEPT A
                         COMPUTE C= FUNCTION ASIN(A * 3.14159 / 180)
                           END-COMPUTE
                           COMPUTE C= (C / 3.14159 * 180)
                          DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY "COS^-1 OF " A " RESULTS..."
                           DISPLAY C " DEGREES"
                               ELSE
                                   IF INPUT1 = 14
                           DISPLAY "TAN^-1 OF..."
                           ACCEPT A
                       COMPUTE C= FUNCTION ATAN(A)
                           END-COMPUTE
                           COMPUTE C= (C / 3.14159 * 180)
                          DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY "LA TAN^-1 " A " RESULTS..."
                           DISPLAY C " DEGREES"
                END-IF
               END-IF
              END-IF
             END-IF
            END-IF
           END-IF
          END-IF.
              STOP RUN.

现在,我要给出一条消息,“您是否要执行其他操作?”并且,如果答案是肯定的,则返回到开头,如果您回答“否”,则返回到结尾,可能添加类似

接受输入1

显示“您是否还想进行其他计算?

如果INPUT1 = YES(返回到开头)

如果INPUT 1 = NO STOP RUN。 (很抱歉,这种编写方式会给您带来更多的代码框,但是atack并没有让您离开)

This is the github link: https://github.com/aIDserse/Super-utility-Submachine-COBOL-CALCULATOR

评论