title: Cobol, Finding a Percentage
body: <p>I'm working on an assignment for my class, and I'm having an issue with getting a percentage to show the proper value for my COBOL Lab.</p>
  
  <p>My issue is with PERCENT-DISCOUNT / WS-PERCENT-WITH-DISCOUNT (at least, I believe it is).</p>
  
  <p>When the program is run, I get the result 50.0. The result I should be getting (assuming I did the math correctly by hand) is 55.6. I'm not too sure where I'm going wrong.</p>
  
  <p>Here is the code that I currently have written for the program.</p>
  
  <pre><code>  *
     IDENTIFICATION DIVISION.
     PROGRAM-ID. LAB2.
     AUTHOR. XXXXXXX XXXXXXXXXXX.
  
    *
     ENVIRONMENT DIVISION.
     INPUT-OUTPUT SECTION.
     FILE-CONTROL.
  
         SELECT IPT-FILE ASSIGN TO 'LAB2.DAT'
             ORGANIZATION IS LINE SEQUENTIAL.
  
         SELECT PRT-FILE ASSIGN TO 'LAB2_OUTPUT.DAT'
             ORGANIZATION IS LINE SEQUENTIAL.
  
    *
     DATA DIVISION.
     FILE SECTION.
  
    *
     FD IPT-FILE
         RECORD CONTAINS 80 CHARACTERS
         RECORDING MODE IS F
         DATA RECORD IS INPUT-RECORD.
  
     01 IPT-RECORD.
         05 IPT-INV-NUMBER       PIC 9(04).
         05 IPT-INV-QUANTITY     PIC 9(03).
         05 IPT-INV-DESCRIPTION  PIC X(13).
         05 IPT-INV-UNITPRICE    PIC 9999V99.
         05 IPT-INV-PROD-CLASS   PIC 9(01).
  
    *
     FD PRT-FILE
         RECORD CONTAINS 132 CHARACTERS
         RECORDING MODE IS F
         DATA RECORD IS PRT-LINE.
  
     01 PRT-LINE.
         05 FILLER               PIC X(04).
         05 PRT-INV-NUMBER       PIC 9(04).
         05 FILLER               PIC X(02).
         05 PRT-EXTENDED-PRICE   PIC Z,ZZZ,ZZ9.99.
         05 FILLER               PIC X(04).
         05 PRT-DISCOUNT-AMOUNT  PIC ZZZ,ZZ9.99.
         05 FILLER               PIC X(03).
         05 PRT-NET-PRICE        PIC Z,ZZZ,ZZ9.99.
         05 FILLER               PIC X(10).
         05 PRT-PRODUCT-CLASS    PIC 9.
         05 FILLER               PIC X(07).
         05 PRT-TRANS-PERCENT    PIC Z9.9.
         05 FILLER               PIC X(05).
         05 PRT-TRANS-CHARGE     PIC ZZZ,ZZ9.99.
  
    *
     WORKING-STORAGE SECTION.
    *
     01 EOF-SWITCH               PIC X VALUE 'N'.
  
    *
     01 WS-EXTENDED-COST         PIC 9(07)V99.
  
     01 WS-DISCOUNT-AMOUNT       PIC 9(06)V99.
  
     01 WS-NET-COST              PIC 9(07)V99.
  
     01 WS-TRANS-PERCENT         PIC ZZ9V9.
  
     01 WS-TRANS-COST            PIC 9(06)V99.
  
    *
     01 WS-TOTAL-EXTENDED-COST   PIC 9(09)V99 VALUE ZERO.
  
     01 WS-TOTAL-NET-COST        PIC 9(08)V99 VALUE ZERO.
  
     01 WS-TOTAL-TRANS-COST      PIC 9(08)V99 VALUE ZERO.
  
     01 WS-TOTAL-WITH-DISCOUNT   PIC 99V9 VALUE ZERO.
  
     01 WS-TOTAL-ITEMS           PIC 99V9 VALUE ZERO.
  
     01 WS-PERCENT-WITH-DISCOUNT PIC 99V9.
  
     01 WS-TOTAL-NO-DISCOUNT     PIC 99V9 VALUE ZERO.
  
    *
     01 HEADING-NAME.
         05 MY-NAME              PIC X(20) VALUE
             'XXXXX XXXXXXX, LAB 2'.
  
     01 HEADING-COLUMN-1.
         05 FILLER               PIC X(05) VALUE SPACES.
         05 COLUMN-1-INV-NUM     PIC X(03) VALUE 'INV'.
         05 FILLER               PIC X(06) VALUE SPACES.
         05 COLUMN-1-EXT-PRC     PIC X(08) VALUE 'EXTENDED'.
         05 FILLER               PIC X(06) VALUE SPACES.
         05 COLUMN-1-DISC-AMT    PIC X(08) VALUE 'DISCOUNT'.
         05 FILLER               PIC X(06) VALUE SPACES.
         05 COLUMN-1-NET-PRC     PIC X(09) VALUE 'NET PRICE'.
         05 FILLER               PIC X(06) VALUE SPACES.
         05 COLUMN-1-CLASS       PIC X(05) VALUE 'CLASS'.
         05 FILLER               PIC X(06) VALUE SPACES.
         05 COLUMN-1-TRANS-P     PIC X(05) VALUE 'TRANS'.
         05 FILLER               PIC X(06) VALUE SPACES.
         05 COLUMN-1-TRANS-C     PIC X(14) VALUE 'TRANSPORTATION'.
  
     01 HEADING-COLUMN-2.
         05 FILLER               PIC X(05) VALUE SPACES.
         05 COLUMN-2-INV-NUM     PIC X(03) VALUE 'NUM'.
         05 FILLER               PIC X(09) VALUE SPACES.
         05 COLUMN-2-EXT-PRC     PIC X(08) VALUE 'PRICE'.
         05 FILLER               PIC X(05) VALUE SPACES.
         05 COLUMN-2-DISC-AMT    PIC X(08) VALUE 'AMOUNT'.
         05 FILLER               PIC X(06) VALUE SPACES.
         05 COLUMN-2-NET-PRC     PIC X(09) VALUE SPACES.
         05 FILLER               PIC X(06) VALUE SPACES.
         05 COLUMN-2-CLASS       PIC X(05) VALUE SPACES.
         05 FILLER               PIC X(08) VALUE SPACES.
         05 COLUMN-2-TRANS-P     PIC X(05) VALUE '%'.
         05 FILLER               PIC X(05) VALUE SPACES.
         05 COLUMN-2-TRANS-C     PIC X(14) VALUE 'CHARGE'.
  
     01 BLANK-LINE.
         05  BLANK-SPACE         PIC X VALUE SPACES.
  
     01 TOTAL-FOOTER.
         05 FILLER               PIC X(07) VALUE SPACES.
         05 TOTAL-EXTENDED-COST  PIC $$$$,$$$,$$9.99.
         05 FILLER               PIC X(15) VALUE SPACES.
         05 TOTAL-NET-COST       PIC $$$,$$$,$$9.99.
         05 FILLER               PIC X(23) VALUE SPACES.
         05 TOTAL-TRANS-COST     PIC $$$,$$$,$$9.99.
  
     01 TOTAL-NO-DISCOUNT-FOOTER.
         05 TOTAL-SENTENCE       PIC X(31) VALUE
             'TOTAL ITEMS WITHOUT DISCOUNT = '.
         05 TOTAL-NO-DISCOUNT    PIC Z9.
  
     01 PERCENT-DISCOUNT-FOOTER.
         05 PERCENT-SENTENCE     PIC X(44) VALUE
             'PERCENT OF ITEMS THAT RECEIVED A DISCOUNT = '.
         05 PERCENT-DISCOUNT     PIC Z9.9.
  
    *
     PROCEDURE DIVISION.
    *
         OPEN INPUT IPT-FILE.
         OPEN OUTPUT PRT-FILE.
  
    *
         WRITE PRT-LINE FROM HEADING-NAME AFTER ADVANCING 0 LINES.
         WRITE PRT-LINE FROM HEADING-COLUMN-1 AFTER ADVANCING 3 LINES.
         WRITE PRT-LINE FROM HEADING-COLUMN-2 AFTER ADVANCING 1 LINES.
         WRITE PRT-LINE FROM BLANK-LINE AFTER ADVANCING 1 LINES.
  
    *
         READ IPT-FILE AT END MOVE 'Y' TO EOF-SWITCH.
  
    *
         PERFORM MAIN-LOOP UNTIL EOF-SWITCH EQUALS 'Y'.
  
    *
         DIVIDE WS-TOTAL-WITH-DISCOUNT BY WS-TOTAL-ITEMS
             GIVING WS-PERCENT-WITH-DISCOUNT.
  
         MULTIPLY WS-PERCENT-WITH-DISCOUNT BY 100
             GIVING WS-PERCENT-WITH-DISCOUNT.
  
    *
         MOVE WS-TOTAL-EXTENDED-COST TO TOTAL-EXTENDED-COST.
         MOVE WS-TOTAL-NET-COST TO TOTAL-NET-COST.
         MOVE WS-TOTAL-TRANS-COST TO TOTAL-TRANS-COST.
         MOVE WS-TOTAL-NO-DISCOUNT TO TOTAL-NO-DISCOUNT.
         MOVE WS-PERCENT-WITH-DISCOUNT TO PERCENT-DISCOUNT.
  
    *
         WRITE PRT-LINE FROM TOTAL-FOOTER AFTER ADVANCING 3 LINES.
         WRITE PRT-LINE FROM TOTAL-NO-DISCOUNT-FOOTER AFTER
             ADVANCING 3 LINES.
         WRITE PRT-LINE FROM BLANK-LINE AFTER ADVANCING 1 LINES.
         WRITE PRT-LINE FROM PERCENT-DISCOUNT-FOOTER AFTER ADVANCING
             1 LINES.
  
    *
         CLOSE IPT-FILE, PRT-FILE.
         STOP RUN.
  
    *
     MAIN-LOOP.
  
         MOVE SPACES TO PRT-LINE.
  
    *
         MULTIPLY IPT-INV-QUANTITY BY IPT-INV-UNITPRICE
             GIVING WS-EXTENDED-COST ROUNDED.
         MOVE WS-EXTENDED-COST TO PRT-EXTENDED-PRICE.
  
    *
         ADD 1 TO WS-TOTAL-ITEMS
  
    *
         IF WS-EXTENDED-COST IS GREATER THAN 200 THEN
             MULTIPLY WS-EXTENDED-COST BY 0.11 GIVING
                 WS-DISCOUNT-AMOUNT ROUNDED
  
             ADD 1 TO WS-TOTAL-WITH-DISCOUNT
    *
         ELSE
             MOVE ZERO TO WS-DISCOUNT-AMOUNT
  
             ADD 1 TO WS-TOTAL-NO-DISCOUNT
  
         END-IF.
  
    *
         IF IPT-INV-PROD-CLASS IS EQUAL TO 1 THEN
             MOVE 27.0 TO WS-TRANS-PERCENT
  
             MULTIPLY WS-EXTENDED-COST BY 0.27 GIVING
                 WS-TRANS-COST ROUNDED
    *
         ELSE IF IPT-INV-PROD-CLASS IS EQUAL TO 2 THEN
             MOVE 17.0 TO WS-TRANS-PERCENT
  
             MULTIPLY WS-EXTENDED-COST BY 0.17 GIVING
                 WS-TRANS-COST ROUNDED
    *
         ELSE IF IPT-INV-QUANTITY IS GREATER THAN 100 THEN
             MOVE 13.5 TO WS-TRANS-PERCENT
  
             MULTIPLY WS-EXTENDED-COST BY 0.135 GIVING
                 WS-TRANS-COST ROUNDED
    *
         ELSE
             MOVE ZERO TO WS-TRANS-PERCENT
             MOVE 25.00 TO WS-TRANS-COST
  
         END-IF.
  
    *
         SUBTRACT WS-EXTENDED-COST FROM WS-DISCOUNT-AMOUNT
             GIVING WS-NET-COST.
  
         ADD WS-EXTENDED-COST TO WS-TOTAL-EXTENDED-COST.
         ADD WS-NET-COST TO WS-TOTAL-NET-COST.
         ADD WS-TRANS-COST TO WS-TOTAL-TRANS-COST.
  
  
    *
         MOVE IPT-INV-NUMBER TO PRT-INV-NUMBER.
         MOVE WS-EXTENDED-COST TO PRT-EXTENDED-PRICE.
         MOVE WS-DISCOUNT-AMOUNT TO PRT-DISCOUNT-AMOUNT.
         MOVE WS-NET-COST TO PRT-NET-PRICE.
         MOVE IPT-INV-PROD-CLASS TO PRT-PRODUCT-CLASS.
         MOVE WS-TRANS-PERCENT TO PRT-TRANS-PERCENT.
         MOVE WS-TRANS-COST TO PRT-TRANS-CHARGE.
  
    *
         WRITE PRT-LINE AFTER ADVANCING 1 LINES.
  
    *
         READ IPT-FILE AT END MOVE 'Y' TO EOF-SWITCH.
  </code></pre>
  
  <p>Here is the information that the .dat file holds.</p>
  
  <pre><code>2047105TYPEWRITER   0800002
  1742010HANDLE       0010001
  2149150USB DRIVE    1200003
  3761005TAPE         5000004
  2791010BOLTS        0000751
  3000100STAPLER      0002007
  3001101OVERHEAD PROJ0099997
  3002099PENCILS      0000097
  4001184CANADIAN RUGS0150294
  4003050CARPET       0040000
  4005001WASTE BASKETS0003793
  5001010HINGES       0010001
  5003010PENS (GOLD)  0049992
  5004400PENS (BLACK) 0002004
  8888999HIGH CHAIR   9999991
  8889412PLAY PEN     0074992
  0001001LOW TEST     0000019
  9999999LAST RECORD  0000011
  </code></pre>