IDENTIFICATION DIVISION.
PROGRAM-ID. CalculateTotalCost.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT PRODUCTS-FILE ASSIGN TO 'PRODUCTS.DAT' ORGANIZATION IS LINE SEQUENTIAL.
    SELECT TOTAL-COST-FILE ASSIGN TO 'TOTAL_COST.TXT' ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD PRODUCTS-FILE.
01 PRODUCT-RECORD.
   05 PRODUCT-NAME PIC X(20).
   05 PRODUCT-PRICE PIC 9(3)V99.

FD TOTAL-COST-FILE.
01 TOTAL-COST-RECORD PIC 9(5)V99.

WORKING-STORAGE SECTION.
01 TOTAL-COST PIC 9(5)V99 VALUE 0.
01 END-OF-FILE PIC X VALUE 'N'.
   88 EOF VALUE 'Y'.
   88 NOT-EOF VALUE 'N'.

PROCEDURE DIVISION.
000-MAIN.
    OPEN INPUT PRODUCTS-FILE
         OUTPUT TOTAL-COST-FILE
    PERFORM UNTIL EOF
        READ PRODUCTS-FILE INTO PRODUCT-RECORD
            AT END
                SET EOF TO TRUE
            NOT AT END
                DISPLAY "Read Product: " PRODUCT-NAME " Price: " PRODUCT-PRICE
                ADD PRODUCT-PRICE TO TOTAL-COST
        END-READ
    END-PERFORM

    DISPLAY "Total Cost: " TOTAL-COST
    WRITE TOTAL-COST-RECORD FROM TOTAL-COST

    CLOSE PRODUCTS-FILE
          TOTAL-COST-FILE
    STOP RUN.
