Logo 
Search:

Cobol Answers

Ask Question   UnAnswered
Home » Forum » Cobol       RSS Feeds
  Question Asked By: Ajay Unnam   on Jul 04 In Cobol Category.

  
Question Answered By: Ajay Unnam   on Jul 04

IDENTIFICATION DIVISION.
PROGRAM-ID. CONVERT.

ENVIRONMENT DIVISION.

DATA DIVISION.
WORKING-STORAGE SECTION.
77 NUM PIC 9(12).
77 N PIC 9 VALUE 0.
77 J PIC 9.
77 AMOUNT PIC X(120) VALUE SPACES.
77 S PIC X(2) VALUE SPACES.
77 L PIC X(12) VALUE SPACES.
77 T PIC X(12) VALUE SPACES.
77 H PIC X(12) VALUE SPACES.
77 NUM1 PIC 9(12).
77 QU PIC 9(12).
77 REM PIC 9.
77 S1 PIC X(12) VALUE SPACES.
77 S2 PIC X(12) VALUE SPACES.
77 S3 PIC X(12) VALUE SPACES.
77 S4 PIC X(12) VALUE SPACES.
77 S5 PIC X(12) VALUE SPACES.
77 S6 PIC X(12) VALUE SPACES.
77 S7 PIC X(12) VALUE SPACES.

01 REMN.
02 D PIC 9 OCCURS 7 TIMES.

PROCEDURE DIVISION.
MAIN-PARA.

DISPLAY "-----------".
DISPLAY "ENTER YOUR 7 DIGIT NUMBER".
ACCEPT NUM.
DISPLAY "-----------".
MOVE NUM TO NUM1.
PERFORM DIGIT UNTIL NUM = 0.
IF NUM1 = 0 THEN
DISPLAY "ZERO"
STOP RUN.
EVALUATE TRUE
WHEN N = 1 PERFORM ONEDIG
WHEN N = 2 PERFORM TWODIG
WHEN N = 3 PERFORM THREEDIG
WHEN N = 4 PERFORM FOURDIG
WHEN N = 5 PERFORM FIVEDIG
WHEN N = 6 PERFORM SIXDIG
WHEN N = 7 PERFORM SEVENDIG
END-EVALUATE.
PERFORM DISPLAYP.
STOP RUN.

DIGIT.

DIVIDE NUM BY 10 GIVING QU REMAINDER REM.
MOVE QU TO NUM.
COMPUTE N = N + 1.
IF N > 7 THEN
DISPLAY "INVALID ENTRY"
MOVE 0 TO N
PERFORM MAIN-PARA
ELSE
MOVE REM TO D(N)
END-IF.

ONEDIG.

EVALUATE TRUE
WHEN D(1) = 1 MOVE "ONE" TO S1
WHEN D(1) = 2 MOVE "TWO" TO S1
WHEN D(1) = 3 MOVE "THREE" TO S1
WHEN D(1) = 4 MOVE "FOUR" TO S1
WHEN D(1) = 5 MOVE "FIVE" TO S1
WHEN D(1) = 6 MOVE "SIX" TO S1
WHEN D(1) = 7 MOVE "SEVEN" TO S1
WHEN D(1) = 8 MOVE "EIGHT" TO S1
WHEN D(1) = 9 MOVE "NINE" TO S1
END-EVALUATE.

TWODIG.

IF D(2) NOT EQUAL TO ZERO
THEN
IF D(2) = 1 THEN
EVALUATE TRUE
WHEN D(1) = 1 MOVE "ELEVEN" TO S2
WHEN D(1) = 2 MOVE "TWELVE" TO S2
WHEN D(1) = 3 MOVE "THIRTEEN" TO S2
WHEN D(1) = 4 MOVE "FOURTEEN" TO S2
WHEN D(1) = 5 MOVE "FIFTEEN" TO S2
WHEN D(1) = 6 MOVE "SIXTEEN" TO S2
WHEN D(1) = 7 MOVE "SEVENTEEN" TO S2
WHEN D(1) = 8 MOVE "EIGHTEEN" TO S2
WHEN D(1) = 9 MOVE "NINETEEN" TO S2
WHEN D(1) = 0 MOVE "TEN" TO S2
END-EVALUATE
ELSE
EVALUATE TRUE
WHEN D(2) = 2 MOVE "TWENTY" TO S2
WHEN D(2) = 3 MOVE "THIRTY" TO S2
WHEN D(2) = 4 MOVE "FORTY" TO S2
WHEN D(2) = 5 MOVE "FIFTY" TO S2
WHEN D(2) = 6 MOVE "SIXTY" TO S2
WHEN D(2) = 7 MOVE "sEVENTY" TO S2
WHEN D(2) = 8 MOVE "EIGHTY" TO S2
WHEN D(2) = 9 MOVE "NINETY" TO S2
END-EVALUATE
PERFORM ONEDIG
END-IF.

THREEDIG.

IF D(3) NOT EQUAL TO ZERO THEN
EVALUATE TRUE
WHEN D(3) = 1 MOVE "ONE" TO S3
WHEN D(3) = 2 MOVE "TWO" TO S3
WHEN D(3) = 3 MOVE "THREE" TO S3
WHEN D(3) = 4 MOVE "FOUR" TO S3
WHEN D(3) = 5 MOVE "FIVE" TO S3
WHEN D(3) = 6 MOVE "SIX" TO S3
WHEN D(3) = 7 MOVE "SEVEN" TO S3
WHEN D(3) = 8 MOVE "EIGHT" TO S3
WHEN D(3) = 9 MOVE "NINE" TO S3
END-EVALUATE
MOVE "HUNDREAD" TO H
PERFORM TWODIG
ELSE
PERFORM TWODIG
END-IF.

FOURDIG.

IF D(4) NOT EQUAL TO ZERO
THEN
EVALUATE TRUE
WHEN D(4) = 1 MOVE "ONE" TO S4
WHEN D(4) = 2 MOVE "TWO" TO S4
WHEN D(4) = 3 MOVE "THREE" TO S4
WHEN D(4) = 4 MOVE "FOUR" TO S4
WHEN D(4) = 5 MOVE "FIVE" TO S4
WHEN D(4) = 6 MOVE "SIX" TO S4
WHEN D(4) = 7 MOVE "SEVEN" TO S4
WHEN D(4) = 8 MOVE "EIGHT" TO S4
WHEN D(4) = 9 MOVE "NINE" TO S4
END-EVALUATE
MOVE "THOUSAND" TO T
PERFORM THREEDIG
ELSE
PERFORM THREEDIG
END-IF.

FIVEDIG.

IF D(5) NOT EQUAL TO ZERO
THEN
IF D(5) = 1 THEN
EVALUATE TRUE
WHEN D(4) = 1 MOVE "ELEVEN" TO S5
WHEN D(4) = 2 MOVE "TWELVE" TO S5
WHEN D(4) = 3 MOVE "THIRTEEN" TO S5
WHEN D(4) = 4 MOVE "FOURTEEN" TO S5
WHEN D(4) = 5 MOVE "FIFTEEN" TO S5
WHEN D(4) = 6 MOVE "SIXTEEN" TO S5
WHEN D(4) = 7 MOVE "SEVENTEEN" TO S5
WHEN D(4) = 8 MOVE "EIGHTEEN" TO S5
WHEN D(4) = 9 MOVE "NINETEEN" TO S5
WHEN D(4) = 0 MOVE "TEN" TO S5
END-EVALUATE
ELSE
EVALUATE TRUE
WHEN D(5) = 2 MOVE "TWENTY" TO S5
WHEN D(5) = 3 MOVE "THIRTY" TO S5
WHEN D(5) = 4 MOVE "FORTY" TO S5
WHEN D(5) = 5 MOVE "FIFTY" TO S5
WHEN D(5) = 6 MOVE "SIXTY" TO S5
WHEN D(5) = 7 MOVE "SEVENTY" TO S5
WHEN D(5) = 8 MOVE "EIGHTY" TO S5
WHEN D(5) = 9 MOVE "NINETY" TO S5
END-EVALUATE
EVALUATE TRUE
WHEN D(4) = 1 MOVE "ONE" TO S4
WHEN D(4) = 2 MOVE "TWO" TO S4
WHEN D(4) = 3 MOVE "THREE" TO S4
WHEN D(4) = 4 MOVE "FOUR" TO S4
WHEN D(4) = 5 MOVE "FIVE" TO S4
WHEN D(4) = 6 MOVE "SIX" TO S4
WHEN D(4) = 7 MOVE "SEVEN" TO S4
WHEN D(4) = 8 MOVE "EIGHT" TO S4
WHEN D(4) = 9 MOVE "NINE" TO S4
END-EVALUATE
END-IF
MOVE "THOUSAND" TO T
PERFORM FOURDIG
END-IF.

SIXDIG.

IF D(6) NOT EQUAL TO ZERO
THEN
EVALUATE TRUE
WHEN D(6) = 1 MOVE "ONE" TO S6
WHEN D(6) = 2 MOVE "TWO" TO S6
WHEN D(6) = 3 MOVE "THREE" TO S6
WHEN D(6) = 4 MOVE "FOUR" TO S6
WHEN D(6) = 5 MOVE "FIVE" TO S6
WHEN D(6) = 6 MOVE "SIX" TO S6
WHEN D(6) = 7 MOVE "SEVEN" TO S6
WHEN D(6) = 8 MOVE "EIGHT" TO S6
WHEN D(6) = 9 MOVE "NINE" TO S6
END-EVALUATE
MOVE "LAKH" TO L
PERFORM FIVEDIG
ELSE
PERFORM FIVEDIG
END-IF.

SEVENDIG.

IF D(7) NOT EQUAL TO ZERO
THEN
IF D(7) = 1 THEN
EVALUATE TRUE
WHEN D(6) = 1 MOVE "ELEVEN" TO S7
WHEN D(6) = 2 MOVE "TWELVE" TO S7
WHEN D(6) = 3 MOVE "THIRTEEN" TO S7
WHEN D(6) = 4 MOVE "FOURTEEN" TO S7
WHEN D(6) = 5 MOVE "FIFTEEN" TO S7
WHEN D(6) = 6 MOVE "SIXTEEN" TO S7
WHEN D(6) = 7 MOVE "SEVENTEEN" TO S7
WHEN D(6) = 8 MOVE "EIGHTEEN" TO S7
WHEN D(6) = 9 MOVE "NINETEEN" TO S7
WHEN D(6) = 0 MOVE "TEN" TO S7
END-EVALUATE
ELSE
EVALUATE TRUE
WHEN D(7) = 2 MOVE "TWENTY" TO S7
WHEN D(7) = 3 MOVE "THIRTY" TO S7
WHEN D(7) = 4 MOVE "FORTY" TO S7
WHEN D(7) = 5 MOVE "FIFTY" TO S7
WHEN D(7) = 6 MOVE "SIXTY" TO S7
WHEN D(7) = 7 MOVE "SEVENTY" TO S7
WHEN D(7) = 8 MOVE "EIGHTY" TO S7
WHEN D(7) = 9 move "NINETY" TO S7
END-EVALUATE
EVALUATE TRUE
WHEN D(6) = 1 MOVE "ONE" TO S6
WHEN D(6) = 2 MOVE "TWO" TO S6
WHEN D(6) = 3 MOVE "THREE" TO S6
WHEN D(6) = 4 MOVE "FOUR" TO S6
WHEN D(6) = 5 MOVE "FIVE" TO S6
WHEN D(6) = 6 MOVE "SIX" TO S6
WHEN D(6) = 7 MOVE "SEVEN" TO S6
WHEN D(6) = 8 MOVE "EIGHT" TO S6
WHEN D(6) = 9 MOVE "NINE" TO S6
END-EVALUATE
END-IF
MOVE "LAKH" TO L
PERFORM FIVEDIG
ELSE
PERFORM SIXDIG
END-IF.

DISPLAYP.

STRING S7 DELIMITED BY SPACE
S6 DELIMITED BY SPACE
S DELIMITED BY SIZE
L DELIMITED BY SPACE
S DELIMITED BY SIZE
S5 DELIMITED BY SPACE
S4 DELIMITED BY SPACE
S DELIMITED BY SIZE
T DELIMITED BY SPACE
S DELIMITED BY SIZE
S3 DELIMITED BY SPACE
S DELIMITED BY SIZE
H DELIMITED BY SPACE
S DELIMITED BY SIZE
S2 DELIMITED BY SPACE
S DELIMITED BY SIZE
S1 DELIMITED BY SPACE INTO AMOUNT.
DISPLAY AMOUNT.

Share: 

 
 
Didn't find what you were looking for? Find more on Program Or get search suggestion and latest updates.


Tagged: