Introduction
Payroll is a classic business application in which correctness matters. This project computes salary components from rules kept in a table, so changing a tax slab is a data change, not a code change.
Problem statement
Objectives
- Encode business rules in data tables
- Implement progressive (slab) tax calculation
- Format financial reports
- Export data for other tools
Features
- Payslip for any employee
- Slab-based annual tax converted to a monthly amount
- Payroll register with column totals
- CSV export
- Duplicate ID protection
Concepts demonstrated
- Table-driven design
- Structs
- Progressive taxation
- Report formatting
System architecture
SLABS[] lists each slab's upper limit and rate. annual_tax walks the slabs, taxing only the part of income inside each, then adds cess. compute builds a Payslip struct from an Employee; payslips, the register and the CSV all reuse it.
Folder structure
Complete source code
Makefile
What each file does
- src/main.c
- The slab table,
annual_tax,compute, payslip/register printing and CSV export. - Makefile
- Build automation:
makebuilds./app,make testruns the sample session and compares it with the expected output,make cleanremoves build files.
How to run it
Build
Run
Test against the expected output
Expected output
Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.
1 1 Priya Engineering 60000 1 2 Arjun Sales 32000 1 3 Neha Engineering 125000 2 1 3 4 0
Testing
- Diff with
tests/expected-output.txt. - Check by hand: gross 91,200/month → taxable 10,19,400/year → tax 52,910 + 4% cess = 55,026.40/year = 4,585.53/month.
- Open payroll.csv in a spreadsheet.
Common errors
Tax is far too high
Each slab rate applies only to the income inside that slab, not to the whole income.
Names with spaces break input
This simplified reader takes one-word names; extend it to read lines with fgets.
Possible improvements
- Monthly attendance and loss-of-pay days
- Store employees in a file
- Compare old and new tax regimes
Additional challenges
- 1Add overtime pay at 1.5× the hourly rate.
- 2Generate each payslip as a separate text file.
- 3Support arrears when a salary revision is back-dated.
Built and tested it yourself? Mark it to update your dashboard.