Count Vowels
Problem Description
Count the number of vowels in a given string.
Expected Output
Input: HELLO WORLD -> Output: VOWELS = 3
Hints
Use INSPECT TALLYING for each vowel.
Solution
IDENTIFICATION DIVISION.
PROGRAM-ID. VOWELCNT.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-INPUT PIC X(100).
01 WS-COUNT PIC 9(3) VALUE 0.
PROCEDURE DIVISION.
DISPLAY "ENTER A STRING: ".
ACCEPT WS-INPUT.
INSPECT WS-INPUT TALLYING WS-COUNT
FOR ALL "A" "E" "I" "O" "U"
"a" "e" "i" "o" "u".
DISPLAY "VOWEL COUNT = " WS-COUNT.
STOP RUN.
Explanation:
INSPECT TALLYING counts occurrences. FOR ALL counts each character.