Accept User Input
Problem Description
Write a program that accepts a user's name and displays a personalized greeting.
Expected Output
Enter name, then see: WELCOME, [NAME]!
Hints
Use ACCEPT to get input and store in a variable defined in WORKING-STORAGE.
Solution
IDENTIFICATION DIVISION.
PROGRAM-ID. GREETING.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NAME PIC X(30).
PROCEDURE DIVISION.
DISPLAY "ENTER YOUR NAME: ".
ACCEPT WS-NAME.
DISPLAY "WELCOME, " WS-NAME "!".
STOP RUN.
Explanation:
ACCEPT reads input from SYSIN. The variable WS-NAME is defined as 30 characters.