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
- Data items for hours, rate and pay
- A calculation with
COMPUTE - A printed pay slip
Steps
- Read WORKING-STORAGE:
PIC 99holds two digits. COMPUTE PAY = HOURS * RATEdoes the maths.- Press Run to see the pay slip.
- 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
- Add overtime pay for hours above 40.
- Add a tax amount.
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.