Logo 
Search:

Cobol Articles

Submit Article
Home » Articles » Cobol » Homework HelpRSS Feeds

PROGRAM FOR CONVERTIONG INTEGER TO ITS NUMBER OF WORDS

Posted By: Adelbert Fischer     Category: Cobol     Views: 5456

WRITE A PROGRAM FOR CONVERTIONG INTEGER TO ITS NO. OF WORDS.

Code for PROGRAM FOR CONVERTIONG INTEGER TO ITS NUMBER OF WORDS in Cobol

       identification division.
       program-id. number1.

       data division.
       working-storage section.
          77 char-pos   pic 99 comp.
          77 temp       pic x(14).
          77 j          pic 99.

       01 numb.
          05 thousands  pic 99.
          05 hundreds   pic 9.
          05 tens       pic 99.

       01 numb-in-words pic x(60).

       01 table-1 value"One    Two    Three  Four   Five   Six   Seven "
      -    "Eight  Nine  ".
          05 p pic x(6) occurs 9 times.

       01 table-2 value"Ten       Eleven    Twelve    Thirteen  Fourteen  "
      -   "Fifteen   Sixteen   Seventeen Eighteen  Ninteen   ".
          05 q pic x(10) occurs 10 times.

       01 table-3 value"Twenty    Thirty    Fourty    Fifty     Sixty     "
      -    "Seventy   Eighty    Ninty     ".
          05 r pic x(10) occurs 8 times.

       01 digits.
          05 d1 pic 9.
          05 d2 pic 9.

           procedure division.
       get-numb.
          display "Number [5 digits Only]: " with no advancing.
          accept numb.

       myinitialize.
          move spaces to numb-in-words.
          move 1 to char-pos.

          if numb=0
               move "zero" to numb-in-words
               go to display-numb
          end-if.

          display-thousands.
               if thousands not equal to zero
                    move thousands to digits
                    perform convert-and-concat
                         move "Thousands" to temp
                         perform concat.
          
          display-hundreds.
               if hundreds not equal to zero
                    move p(hundreds) to temp
                    perform concat
                         move "Hundreds" to temp
                         perform concat.

          display-tens.
               if tens not equal to zero
                    move tens to digits
                    perform convert-and-concat.

          display-numb.
               display numb," ",numb-in-words.
               stop run.

          convert-and-concat.
               if d1 is greater than 1
                    subtract 1 from d1 giving j
                    move r(j) to temp
                    perform concat.

               if d1 is equal to 1
                    add 1 d2 giving j
                    move q(j) to temp
                    perform concat
               elseif d2 is not equal to zero
                         move p(d2) to temp
                         perform concat.


          concat.
               string temp delimited by " "
                    into numb-in-words
                    with pointer char-pos.
                    add 1 to char-pos.
  
Share: 


Didn't find what you were looking for? Find more on PROGRAM FOR CONVERTIONG INTEGER TO ITS NUMBER OF WORDS Or get search suggestion and latest updates.

Adelbert Fischer
Adelbert Fischer author of PROGRAM FOR CONVERTIONG INTEGER TO ITS NUMBER OF WORDS is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!