real language

Bookmarking Digg Diigo DZone Earthlink Google
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Cobol

("Pretty" version)

Author:Sumanta Mukhopadhyay
Score: (2.97 in 36 votes)
 Id Division.                                                     
 Program-Id. BotBeer.                                             
 Data Division.                                                   
 Working-Storage Section.                                         
 01  strings.                                                     
     05  buffer                      pic x(80).                   
     05  bb1 value spaces            pic x(15).                   
     05  bb2 value 'bottles of beer' pic x(15).                   
     05  bb3 value 'on the wall'     pic x(11).                   
     05  bb4 value 'Take one down, pass it around, '  pic x(31).  
     05  bb6.                                                     
         10                          pic x(009) value spaces.     
         10                          pic x(117) value             
     'one      two      three    four     five     six      seven 
-    '   eight    nine     ten      eleven   twelve   thirteen'.  
         10                          pic x(054) value             
     'fourteen fifteen  sixteen  seventeeneighteen nineteen'.     
     05  redefines bb6.                                           
         10  bb7 occurs 20           pic x(09).                   
     05  value '              twenty thirty forty  fifty  sixty  s
-              'eventyeighty ninety '.                            
         10  bb8 occurs 10          pic x(07).                    
 01  integers                       binary.                       
     05  i                          pic s9(3).                    
     05  j                          pic s9(3).                    
     05  k                          pic s9(3).                    
     05  l                          pic s9(3).                    
 Procedure Division.                                              
     perform varying i from 99 by -1 until i = 1                  
        move spaces to buffer bb1                                 
        move 1 to j                                               
        divide i by 10 giving k remainder l                       
        string bb8(k + 1) delimited space into bb1 pointer j      
        if j > 1                                                  
           then move bb7(l + 1) to bb1(j + 1:)                    
           else move bb7(i + 1) to bb1                            
        move 1 to j                                               
        string bb1 ' ' bb2 ' ' bb3 delimited '  '                 
           into buffer pointer j                                  
        if i < 99                                                 
           move '!' to buffer(j:)                                 
           display bb4 buffer                                     
           display ' '                                            
        string ', ' bb1 ' ' bb2 '!'                               
           delimited '  ' into buffer pointer j                   
        display function upper-case(buffer(1:1)) buffer(2:)       
     display bb4 'one bottle of beer on the wall!'                
     display ' '                                                  
     display 'One bottle of beer on the wall, one bottle of beer!'
     display 'Take that down, pass it around, '                   
             'no more bottles of beer on the wall!'               
     display ' '                                                  
     display 'No bottle of beer on the wall, '                
             'no more bottles of beer!'                       
     display 'Go to the store and buy some more, '            
             'ninety nine bottles of beer on the wall!'       
     stop run                                                 
 end program BotBeer.

Download Source | Write Comment

Alternative Versions

Short Version with Descriptive Varnames.Joseph James Frantz07/14/0817
2Donald Fraser04/20/056
Typical of mainframe COBOL programsBill Bass04/24/088


>>  pravin said on 02/01/08 04:59:56

pravin wow, i hate computers
i like studying more

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!




Security Code: