Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
*> Program Name: COBOLSum
*> Author: Joshua Smith
*> Class - Principles of Programming Languages
*> Description: This COBOL application gathers 3 numeric inputs (single digit) from the user, sums them up, then repeats what the user entered and the sum back to the user.
IDENTIFICATION DIVISION.
*>Program Name is here
PROGRAM-ID. COBOLSum.
DATA DIVISION.
WORKING-STORAGE SECTION.
*> 4 integer variables: num1, num2, and num3 are all single-digit (0-9), while total is 2-digits (0-99)
01 num1 PIC 9.
01 num2 PIC 9.
01 num3 PIC 9.
01 total PIC 99.
PROCEDURE DIVISION.
*> Start of Procedures
*> Header Displayed to the user (name of program and author, formatted)
DISPLAY "*****************************"
DISPLAY "*---------COBOL SUM---------*"
DISPLAY "*------By Joshua Smith------*"
DISPLAY "*****************************"
*> Prompt the user for the first number and store it in num1.
DISPLAY "*Number 1: (shown in STDIN) *".
ACCEPT num1
*> Prompt the user for the second number and store it in num2.
DISPLAY "*Number 2: (shown in STDIN) *".
ACCEPT num2
*> Prompt the user for the third number and store it in num3.
DISPLAY "*Number 3: (shown in STDIN) *".
ACCEPT num3
*> Simple formatting line
DISPLAY "*---------------------------* ".
*> Compute the sum of the three numeric values, num1, num2, and num3
COMPUTE total = num1 + num2 + num3
*> Display the first value the user entered.
DISPLAY "Number 1: " WITH NO ADVANCING
DISPLAY num1
*> Display the second value the user entered.
DISPLAY "Number 2: " WITH NO ADVANCING
DISPLAY num2
*> Display the third value the user entered.
DISPLAY "Number 3: " WITH NO ADVANCING
DISPLAY num3
*> Display the computed total
DISPLAY "Total: : " WITH NO ADVANCING
DISPLAY total
*> End of program
STOP RUN.
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more