    PRINT "Input filename"
    INPUT file$
    PRINT "Input type of expense"
    INPUT kind$
    PROCinit
    f% = OPENIN file$
    IF f% = 0 THEN
      ERROR 100,"Cannot open "+file$
    ENDIF
    WHILE NOT EOF#f%
       PROCread(GET$#f%,kind$)
    ENDWHILE
    CLOSE#f%
    PROCoutput
    END
    
    DEF PROCinit
      Max_employees% = 255
      eptr% = 0
      DIM Name$(Max_employees%), Expense(Max_employees%)
    ENDPROC
    
    DEF PROCread(a$,kind$)
        LOCAL i%,name$,val,type$
        i% = INSTR(a$,CHR$(34))
        a$ = MID$(a$,i%+1)
        i% = INSTR(a$,CHR$(34))
        name$ = LEFT$(a$,i%-1)
        a$ = MID$(a$,i%+1)
        i% = INSTR(a$,CHR$(44))
        a$ = MID$(a$,i%+1)
        val = VAL(a$)
        i% = INSTR(a$,CHR$(34))
        a$ = MID$(a$,i%+1)
        i% = INSTR(a$,CHR$(34))
        type$ = LEFT$(a$,i%-1)
        IF type$ = kind$ THEN PROCinsert(name$, val)
    ENDPROC
    
    DEF PROCinsert(name$,val)
        LOCAL e%
        e% = FNfind(name$)
        IF e% < eptr% THEN
          Expense(e%) += val
        ELSE
         IF eptr% > Max_employees% THEN
           ERROR 10 ,"Start again with a bigger Max_employees%"
         ENDIF     
         Name$(eptr%) = name$
         Expense(eptr%) = val
         eptr% += 1
        ENDIF
    ENDPROC
    
    DEF FNfind(name$)
        LOCAL i%
        i% = -1
        REPEAT
         i% += 1
        UNTIL Name$(i%) = name$ OR i% >= eptr%
        = i%
    
    DEF PROCoutput
        LOCAL i%
        FOR i% = 0 TO eptr%-1
         PRINT Name$(i%),SPC(6),Expense(i%)
        NEXT
    ENDPROC
