I am trying to implement a simple calculator in COBOL and struggling with a particular issue.
My compiler, GNU Cobol 3.2.0 is always giving me this issue and I do not know how to fix ist.
The error is:
jdoodle.cobc:132: error: multiple PROGRAM-ID’s without matching END PROGRAM
130 | exit program.
131 |
132 >
My code:
identification division.
program-id. taschenrechner.
data division.
working-storage section.
01 zahl_1 pic 9(10).
01 zahl_2 pic 9(10).
01 ergebnis pic 9(10).
01 rechenoperator pic 9(10).
01 clear_screen_counter pic 9(10).
01 zahl_1_str pic z.
01 zahl_2_str pic z.
01 ergebnis_str pic z.
procedure division.
*> Rechenoperation abfragen
*> Rechenoperationen in vier verschiedenen Methoden implementieren
*> Ergebnis returnen
display 'Taschenrechner in COBOL.'.
display ' '.
display 'Bitte wählen Sie einer der folgenden Optionen aus:'.
display ' '.
display 'Tippen Sie 1 für Addition'.
display 'Tippen Sie 2 für Subtraktion'.
display 'Tippen Sie 3 für Multiplikation'.
display 'Tippen Sie 4 für Division'.
display ' '.
move 1 to rechenoperator.
display 'Geben Sie die erste Zahl ein:'.
move 1 to zahl_1.
display 'Geben Sie die zweite Zahl ein:'.
move 1 to zahl_2.
identification division.
program-id. addition.
data division.
linkage section.
01 zahl_1 pic 9(10).
01 zahl_2 pic 9(10).
01 ergebnis pic 9(10).
01 zahl_1_str pic z.
01 zahl_2_str pic z.
01 ergebnis_str pic z.
procedure division.
add zahl_1 to zahl_2 giving ergebnis.
display '----------------------------------------------------------------------------------------------'
display 'Das Ergebnis der Addition zwischen ' zahl_1_str ' und ' zahl_2_str ' lautet: ' ergebnis_str.
display '----------------------------------------------------------------------------------------------'
exit program.
identification division.
program-id. subtraktion.
data division.
linkage section.
01 zahl_1 pic 9(10).
01 zahl_2 pic 9(10).
01 ergebnis pic 9(10).
01 zahl_1_str pic z.
01 zahl_2_str pic z.
01 ergebnis_str pic z.
procedure division.
subtract zahl_1 from zahl_2 giving ergebnis.
display '----------------------------------------------------------------------------------------------'
display 'Das Ergebnis der Subtraktion zwischen ' zahl_1_str ' und ' zahl_2_str ' lautet: ' ergebnis_str.
display '----------------------------------------------------------------------------------------------'
exit program.
identification division.
program-id. multiplikation.
data division.
linkage section.
01 zahl_1 pic 9(10).
01 zahl_2 pic 9(10).
01 ergebnis pic 9(10).
01 zahl_1_str pic z.
01 zahl_2_str pic z.
01 ergebnis_str pic z.
procedure division.
multiply zahl_1 by zahl_2 giving ergebnis.
display '----------------------------------------------------------------------------------------------'
display 'Das Ergebnis der Multiplikation zwischen ' zahl_1_str ' und ' zahl_2_str ' lautet: ' ergebnis_str.
display '----------------------------------------------------------------------------------------------'
exit program.
identification division.
program-id. division.
data division.
linkage section.
01 zahl_1 pic 9(10).
01 zahl_2 pic 9(10).
01 ergebnis pic 9(10).
01 zahl_1_str pic z.
01 zahl_2_str pic z.
01 ergebnis_str pic z.
procedure division.
divide zahl_1 by zahl_2 giving ergebnis.
display '----------------------------------------------------------------------------------------------'
display 'Das Ergebnis der Division zwischen ' zahl_1_str ' und ' zahl_2_str ' lautet: ' ergebnis_str.
display '----------------------------------------------------------------------------------------------'
exit program.
I would be very thankful if someone could help me out.
I googled and tried to implement fixes that unfortunately did not work.
New contributor
Luka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.