SHARE
TWEET

Untitled

a guest Aug 9th, 2018 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. identification division.
  2. program-id. ninety-nine.
  3. environment division.
  4. data division.
  5. working-storage section.
  6. 01  counter pic 99.
  7.   88 no-bottles-left value 0.
  8.   88 one-bottle-left value 1.
  9.  
  10. 01  parts-of-counter redefines counter.
  11.   05  tens    pic 9.
  12.   05  digits    pic 9.
  13.  
  14. 01  after-ten-words.
  15.   05  filler  pic x(7) value spaces.
  16.   05  filler  pic x(7) value "Twenty".
  17.   05  filler  pic x(7) value "Thirty".
  18.   05  filler  pic x(7) value "Forty".
  19.   05  filler  pic x(7) value "Fifty".
  20.   05  filler  pic x(7) value "Sixty".
  21.   05  filler  pic x(7) value "Seventy".
  22.   05  filler  pic x(7) value "Eighty".
  23.   05  filler  pic x(7) value "Ninety".
  24.   05  filler  pic x(7) value spaces.
  25.  
  26. 01  after-ten-array redefines after-ten-words.
  27.   05  atens occurs 10 times pic x(7).
  28.  
  29. 01  digit-words.
  30.   05  filler  pic x(9) value "One".
  31.   05  filler  pic x(9) value "Two".
  32.   05  filler  pic x(9) value "Three".
  33.   05  filler  pic x(9) value "Four".
  34.   05  filler  pic x(9) value "Five".
  35.   05  filler  pic x(9) value "Six".
  36.   05  filler  pic x(9) value "Seven".
  37.   05  filler  pic x(9) value "Eight".
  38.   05  filler  pic x(9) value "Nine".
  39.   05  filler  pic x(9) value "Ten".
  40.   05  filler  pic x(9) value "Eleven".
  41.   05  filler  pic x(9) value "Twelve".
  42.   05  filler  pic x(9) value "Thirteen".
  43.   05  filler  pic x(9) value "Fourteen".
  44.   05  filler  pic x(9) value "Fifteen".
  45.   05  filler  pic x(9) value "Sixteen".
  46.   05  filler  pic x(9) value "Seventeen".
  47.   05  filler  pic x(9) value "Eighteen".
  48.   05  filler  pic x(9) value "Nineteen".
  49.   05  filler  pic x(9) value spaces.
  50.  
  51. 01  digit-array redefines digit-words.
  52.   05  adigits occurs 20 times   pic x(9).
  53.  
  54. 01  number-name pic x(15).
  55.  
  56. 01  stringified pic x(30).
  57. 01  outline   pic x(50).
  58. 01  other-numbers.
  59.   03  n pic 999.
  60.   03  r pic 999.
  61.  
  62. procedure division.
  63. 100-main section.
  64. 100-setup.
  65.   perform varying counter from 99 by -1 until no-bottles-left
  66.     move spaces to outline
  67.     perform 100-show-number
  68.     string stringified delimited by "|", space, "of beer on the wall" into outline end-string
  69.     display outline end-display
  70.     move spaces to outline
  71.     string stringified delimited by "|", space, "of beer" into outline end-string
  72.     display outline end-display
  73.     move spaces to outline
  74.     move "Take" to outline
  75.     if one-bottle-left
  76.       string outline delimited by space, space, "it" delimited by size, space, "|" into outline end-string
  77.     else
  78.       string outline delimited by space, space, "one" delimited by size, space, "|" into outline end-string
  79.     end-if
  80.     string outline delimited by "|", "down and pass it round" delimited by size into outline end-string
  81.     display outline end-display
  82.     move spaces to outline
  83.     subtract 1 from counter giving counter end-subtract
  84.     perform 100-show-number
  85.     string stringified delimited by "|", space, "of beer on the wall" into outline end-string
  86.     display outline end-display
  87.     add 1 to counter giving counter end-add
  88.     display space end-display
  89.   end-perform.
  90.   display "No more bottles of beer on the wall"
  91.   display "No more bottles of beer"
  92.   display "Go to the store and buy some more"
  93.   display "Ninety-Nine bottles of beer on the wall"
  94.   stop run.
  95.  
  96. 100-show-number.
  97.   if no-bottles-left
  98.     move "No more|" to stringified
  99.   else
  100.     if counter < 20
  101.       string function trim( adigits( counter ) ), "|" into stringified
  102.     else
  103.       if counter < 100
  104.         move spaces to number-name
  105.         string atens( tens ) delimited by space, space delimited by size, adigits( digits ) delimited by space into number-name end-string
  106.         move function trim( number-name) to stringified
  107.         divide counter by 10 giving n remainder r end-divide
  108.         if r not = zero
  109.           inspect stringified replacing first space by "-"
  110.         end-if
  111.         inspect stringified replacing first space by "|"
  112.       end-if
  113.     end-if
  114.   end-if.
  115.   if one-bottle-left
  116.     string stringified delimited by "|", space, "bottle|" delimited by size into stringified end-string
  117.   else
  118.     string stringified delimited by "|", space, "bottles|" delimited by size into stringified end-string
  119.   end-if.
  120.  
  121. 100-end.
  122. end-program.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top