Cobol-从程序中重启
Cobol-Restart from the program
我有一个小问题
我用 cobol 写了一个计算器,我不是很专业
我在这里给你代码:
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.
现在,我想发一条消息说 "Do you want to do other operations?",如果回答是 returns 到开头,如果回答不是,则到最后。
如果你能向我解释如何,但如果可以的话,不要用段落。我可以输入正确的代码吗?
大纲:
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.
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
.
我有一个小问题 我用 cobol 写了一个计算器,我不是很专业 我在这里给你代码:
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.
现在,我想发一条消息说 "Do you want to do other operations?",如果回答是 returns 到开头,如果回答不是,则到最后。 如果你能向我解释如何,但如果可以的话,不要用段落。我可以输入正确的代码吗?
大纲:
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.
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
.