Skip to content
C project #16Intermediate

Employee Payroll System

Compute allowances, PF, professional tax and slab-based income tax, print payslips and a payroll register, and export CSV.

Estimated time
~5 hours to build
Files
5 files · 316 lines
Technologies
C11, CSV

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

Store employees with a monthly basic salary. Compute HRA (40%), DA (12%), gross pay, PF (12% of basic), professional tax and monthly income tax from annual slab rates with a standard deduction and 4% cess. Print payslips and a payroll register with totals, and export the register to CSV.

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

TextProject tree
employee-payroll/
├── README.md
├── Makefile
├── src/main.c
├── tests/expected-output.txt
└── tests/sample-input.txt

Complete source code

Makefile

20 lines
MakefileMakefile
# Generated for KENHOLT Skills. Usage: make | make test | make clean
CC = gcc
CFLAGS = -std=c11 -Wall -Wextra -O2
SRC := $(wildcard src/*.c)
HDR := $(wildcard src/*.h)
ARGS := $(shell cat tests/args.txt 2>/dev/null)
INPUT := $(wildcard tests/sample-input.txt)
app: $(SRC) $(HDR)
$(CC) $(CFLAGS) -Isrc $(SRC) -o app -lm
test: app
./app $(ARGS) $(if $(INPUT),< $(INPUT),) > actual.txt
diff actual.txt tests/expected-output.txt && echo "Test passed: output matches tests/expected-output.txt"
clean:
rm -f app app.exe actual.txt
.PHONY: test clean

What each file does

src/main.c
The slab table, annual_tax, compute, payslip/register printing and CSV export.
Makefile
Build automation: make builds ./app, make test runs the sample session and compares it with the expected output, make clean removes build files.

How to run it

Build

Terminal
gcc -std=c11 -Wall -Wextra -Isrc src/*.c -o app -lm
# or simply: make

Run

Terminal
./app # Linux / macOS
.\app.exe # Windows

Test against the expected output

Terminal
./app < tests/sample-input.txt > actual.txt
diff actual.txt tests/expected-output.txt # no output means they match
# Windows PowerShell:
# Get-Content tests\sample-input.txt | .\app.exe > actual.txt
# Compare-Object (Get-Content actual.txt) (Get-Content tests\expected-output.txt)

Expected output

Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.

Texttests/expected-output.txt
1.Add employee 2.Payslip 3.Payroll register 4.Export CSV 0.Exit
Choice:
ID, name, department, monthly basic:
Added Priya.
1.Add employee 2.Payslip 3.Payroll register 4.Export CSV 0.Exit
Choice:
ID, name, department, monthly basic:
Added Arjun.
1.Add employee 2.Payslip 3.Payroll register 4.Export CSV 0.Exit
Choice:
ID, name, department, monthly basic:
Added Neha.
1.Add employee 2.Payslip 3.Payroll register 4.Export CSV 0.Exit
Choice:
Employee ID:
------------------- PAYSLIP -------------------
Employee: Priya ID: 1 Dept: Engineering
Basic 60000.00
HRA (40%) 24000.00
DA (12%) 7200.00
Gross earnings 91200.00
PF (12% of basic) -7200.00
Professional tax -200.00
Income tax (monthly) -4585.53
NET PAY 79214.47
-----------------------------------------------
1.Add employee 2.Payslip 3.Payroll register 4.Export CSV 0.Exit
Choice:
ID Name Dept Gross Tax Net
1 Priya Engineering 91200.00 4585.53 79214.47
2 Arjun Sales 48640.00 904.28 43695.72
3 Neha Engineering 190000.00 30463.33 144336.67
TOTAL (monthly) 329840.00 35953.15 267246.85
1.Add employee 2.Payslip 3.Payroll register 4.Export CSV 0.Exit
Choice:
Exported 3 employee(s) to payroll.csv.
1.Add employee 2.Payslip 3.Payroll register 4.Export CSV 0.Exit
Choice:
Goodbye.
Input
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

  1. 1Add overtime pay at 1.5× the hourly rate.
  2. 2Generate each payslip as a separate text file.
  3. 3Support arrears when a salary revision is back-dated.

Built and tested it yourself? Mark it to update your dashboard.