The COBOL Programming Language

Accept_Num Example Program


Click below to go directly to a specific section:
Description | Source Code | Sample Run | Program Notes

Description

This program accepts two numbers and adds them together.

Source Code

000100 ID DIVISION.
000200 PROGRAM-ID.  ACCEPT1.
000300 DATA DIVISION.
000400 WORKING-STORAGE  SECTION.
000500 01  WS-FIRST-NUMBER      PIC 9(3).
000600 01  WS-SECOND-NUMBER     PIC 9(3).
000700 01  WS-TOTAL             PIC ZZZ9.
000800*
000900 PROCEDURE DIVISION.
001000 0000-MAINLINE.
001100     DISPLAY 'ENTER A NUMBER: '.
001200     ACCEPT WS-FIRST-NUMBER.
001300*
001400     DISPLAY 'ANOTHER NUMBER: '.
001500     ACCEPT WS-SECOND-NUMBER.
001600*
001700     COMPUTE WS-TOTAL = WS-FIRST-NUMBER + WS-SECOND-NUMBER.
001800     DISPLAY 'THE TOTAL IS: ', WS-TOTAL.
001900     STOP RUN.

Sample Run

ENTER A NUMBER: 7
ANOTHER NUMBER: 7
THE TOTAL IS: 14

Program Notes

This program was tested and run using the RM/1 COBOL compiler.
[Back] [Home]

Last modified: 03:39 PM on 11/09/1996