Cobol-Restart from the program

女生的网名这么多〃 提交于 2021-01-28 23:22:18

问题


I have a little question I wrote a calculator in cobol, and I'm not so expert I give you here the code:

       DISPLAY "CALCOLATRICE".
       DISPLAY "ATTENZIONE, IL RISULTATO NON HA SEGNI!".
       DISPLAY "CHE VUOI FARE?".
       DISPLAY "1 ADDIZIONE".
       DISPLAY "2 SOTTRAZIONE".
       DISPLAY "3 MOLTIPLICAZIONE".
       DISPLAY "4 DIVISIONE". 
       DISPLAY "5 ESCI"
       ACCEPT INPUT1

       IF INPUT1 = 5
            DISPLAY "OK, BUON LAVORO :)"
            STOP RUN
        END-IF.

       IF INPUT1 = 1
       DISPLAY "PRIMO NUMERO"
       ACCEPT A
       DISPLAY "SECONDO NUMERO"
       ACCEPT B
       COMPUTE C= A + B
               DISPLAY "Computing"
               DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY A "+" B  " FA..."         
               DISPLAY C
       ELSE
           IF INPUT1 = 2
               DISPLAY "PRIMO NUMERO"
               ACCEPT A
               DISPLAY "SECONDO NUMERO"
               ACCEPT B
               DISPLAY "Computing"
               DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY A "-" B " FA..."
               COMPUTE C= A - B
               DISPLAY C
                   ELSE
                       IF INPUT1 = 3 
                   DISPLAY "PRIMO NUMERO"
                   ACCEPT A
                   DISPLAY "SECONDO NUMERO"
                   ACCEPT B
                   COMPUTE C= A * B
                          DISPLAY "Computing"
                          DISPLAY "Computing."
                          DISPLAY "Computing.."
                          DISPLAY "Computing..."
                          DISPLAY "Computing...."
                          DISPLAY "Computing....."
                          DISPLAY "Computing......"
                          DISPLAY A "x" B " FA..."
                          DISPLAY C
                       ELSE
                           IF INPUT1 = 4
                           DISPLAY "PRIMO NUMERO"
                           ACCEPT A
                           DISPLAY "SECONDO NUMERO"
                           ACCEPT B
                           COMPUTE C= A / B
                          DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY A ":" B " FA..."
                           DISPLAY C
            END-IF
           END-IF
         END-IF
       END-IF.
       STOP RUN.

Now, I want to give a message saying "Do you want to do other operations?" and, if the answer is yes it returns to the beginning, and if you say no it goes to the end. If you can explain to me how, but not with paragraphs if you can. Can I have the code correct?


回答1:


Now, I want to give a message saying "Do you want to do other operations?" and, if the answer is yes it returns to the beginning, and if you say no it goes to the end. If you can explain to me how, but not with paragraphs if you can. Can I have the code correct?

   DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 INPUT1 PIC 9.
   01 A PIC 9(4).
   01 B PIC 9(4).
   01 C PIC 9(4).
   01 Q PIC X VALUE "N".
   PROCEDURE DIVISION.
       PERFORM WITH TEST AFTER UNTIL INPUT1 = 5 OR Q = "N" OR "n"
           DISPLAY "CALCOLATRICE"
           DISPLAY "ATTENZIONE, IL RISULTATO NON HA SEGNI!"
           DISPLAY "CHE VUOI FARE?"
           DISPLAY "1 ADDIZIONE"
           DISPLAY "2 SOTTRAZIONE"
           DISPLAY "3 MOLTIPLICAZIONE"
           DISPLAY "4 DIVISIONE"
           DISPLAY "5 ESCI"
           ACCEPT INPUT1

           EVALUATE INPUT1
           WHEN 1
               DISPLAY "PRIMO NUMERO"
               ACCEPT A
               DISPLAY "SECONDO NUMERO"
               ACCEPT B
               COMPUTE C= A + B
               DISPLAY "Computing"
               DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY A "+" B  " FA..."
               DISPLAY C
           WHEN 2
               DISPLAY "PRIMO NUMERO"
               ACCEPT A
               DISPLAY "SECONDO NUMERO"
               ACCEPT B
               DISPLAY "Computing"
               DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY A "-" B " FA..."
               COMPUTE C= A - B
               DISPLAY C
           WHEN 3
               DISPLAY "PRIMO NUMERO"
               ACCEPT A
               DISPLAY "SECONDO NUMERO"
               ACCEPT B
               COMPUTE C= A * B
               DISPLAY "Computing"
               DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY A "x" B " FA..."
               DISPLAY C
           WHEN 4
               DISPLAY "PRIMO NUMERO"
               ACCEPT A
               DISPLAY "SECONDO NUMERO"
               ACCEPT B
               COMPUTE C= A / B
               DISPLAY "Computing."
               DISPLAY "Computing.."
               DISPLAY "Computing..."
               DISPLAY "Computing...."
               DISPLAY "Computing....."
               DISPLAY "Computing......"
               DISPLAY A ":" B " FA..."
               DISPLAY C
           WHEN 5
               DISPLAY "OK, BUON LAVORO :)"
           END-EVALUATE
           IF INPUT1 NOT = 5
               DISPLAY "Do you want to do other operations?"
               ACCEPT Q
           END-IF
       END-PERFORM
       STOP RUN
       .



回答2:


Outline:

MOVE 'Y' TO do_work
PERFORM UNTIL do_work <> 'Y'
   display menu
   get response
   EVALUATE response
      WHEN reponse = 5
         MOVE 'N' to do_work
      /* other response processing */
   END-PERFORM
GOBACK.


来源:https://stackoverflow.com/questions/61796161/cobol-restart-from-the-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!