      PROGRAM DTABLE
************************************************************************
* Program to calculate and display a depreciation table using one of   *
* two methods of depreciation:                                         *
*      (1) straight-line                                               *
*      (2) sum-of-the-years'-digits                                     *
* Variable used are:                                                   *
*     PRICE  :  purchase price of item                                 *
*     SALVAG :  and its salvage value                                  *
*     AMOUNT :  amount to be depreciated (PRICE - SALVAG)              *
*     LIFE   :  its useful life                                        *
*     METHOD :  method of depreciation (1 or 2)                        *
*     YEAR   :  number of year in depreciation table                   *
*     SUM    :  1 + 2 + ... + LIFE (for sum-of-years'-digits method)   *
*                                                                      *
* Input:  PRICE, SALVAG, LIFE, and METHOD                              *
* Output: Table showing year number and depreciation for that year     *
************************************************************************

      REAL PRICE, SALVAG, AMOUNT
      INTEGER LIFE, METHOD, YEAR, SUM

* Get the information about the item

      PRINT *, 'ENTER PURCHASE PRICE, USEFUL LIFE, AND SALVAGE VALUE:'
      READ *, PRICE, LIFE, SALVAG

* Calculate amount to be depreciated

      AMOUNT = PRICE - SALVAG

* Get method of depreciation to be used

      PRINT *, 'ENTER:'
      PRINT *, '   1 FOR STRAIGHT-LINE DEPRECIATION'
      PRINT *, '   2 FOR SUM-OF-THE-YEARS''-DIGITS METHOD'
      READ *, METHOD

* If straight-line selected, calculate annual depreciation
* Else calculate SUM for sum-of-the-years'-digits method

      IF (METHOD .EQ. 1) THEN
         DEPREC = AMOUNT / LIFE
      ELSE
         SUM = 0
         DO 10 YEAR = 1, LIFE
            SUM = SUM + YEAR
 10               CONTINUE
      END IF


* Generate the depreciation table

      PRINT *
      PRINT *, 'YEAR   DEPRECIATION'
      PRINT *, '==================='
      DO 20 YEAR = 1, LIFE
         IF (METHOD .EQ. 2) THEN
            DEPREC = (LIFE - YEAR + 1) * AMOUNT / REAL(SUM)
         END IF
         PRINT *, YEAR, '   ', DEPREC
 20   CONTINUE

      END
