codegurukool.com · Free coding tutorials & online compiler

Home › COBOL Tutorial › Live project: Payroll calculator

Live project: Payroll calculator

Calculate an employee's pay with COBOL.

Use the divisions, data items, COMPUTE and DISPLAY to print a pay slip.

What you will build

Steps

  1. Read WORKING-STORAGE: PIC 99 holds two digits.
  2. COMPUTE PAY = HOURS * RATE does the maths.
  3. Press Run to see the pay slip.
  4. Change HOURS and RATE and run again.

Run it

Press Run to see the project work. Then change the data in the editor and run it again.

Challenge

Example code

       IDENTIFICATION DIVISION.
       PROGRAM-ID. PAYROLL.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 HOURS PIC 99 VALUE 40.
       01 RATE  PIC 99 VALUE 15.
       01 PAY   PIC 9999 VALUE 0.
       PROCEDURE DIVISION.
           COMPUTE PAY = HOURS * RATE.
           DISPLAY "Employee: Asha".
           DISPLAY "Hours: " HOURS.
           DISPLAY "Rate: " RATE.
           DISPLAY "Pay: " PAY.
           STOP RUN.

Run this code in the online editor

← COBOL project: payroll report