home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / viscobv6.zip / vac22os2 / ibmcobol / samples / toolkit / rexx / api / rexxcalc / program3.cal < prev    next >
Text File  |  1996-11-19  |  964b  |  20 lines

  1. /* Rexx Calculator program 3 key - average of memory registers       */
  2. parse arg num                          /* get the count of memories  */
  3. numeric digits CalcPrecision()         /* set current precision      */
  4. numeric form value CalcForm()          /* set current form           */
  5.  
  6. if \datatype(num, 'Whole')             /* must be whole number       */
  7.   then return 'Error'                  /* return error indicator     */
  8.  
  9. if num < 1 | num >50                   /* valid for counter          */
  10.   then return 'Error'                  /* return error indicator     */
  11.  
  12. accumulator = 0                        /* start at zero              */
  13.  
  14. do i = 1 to num                        /* loop for given number      */
  15.   'GET' i 'REGISTER'                   /* get next register          */
  16.   accumulator = accumulator + register /* add to total               */
  17. end
  18.  
  19. return accumulator / num               /* return the average         */
  20.