C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Decision Making Programs in C

Calculate bonus for employee based on salary & service years

Introduction

In many organizations, employee bonuses are calculated based on their years of service and current salary.


For example, a simple bonus policy might be:

Years of Service

Bonus Percentage

Less than 3 years

5%

3 to 5 years

10%

6 to 10 years

15%

More than 10 years

20%

Bonus can be calculated as:

Bonus Amount = Salary × Bonus %

Net Pay = Salary + Bonus Amount

Method 1:

C Program: Calculate Bonus Based on Salary & Years of Service

C

#include <stdio.h>

 

int main() {

    float salary, bonus, totalPay;

    int years;

 

    // Input employee details

    printf("Enter basic salary: ");

    scanf("%f", &salary);

    printf("Enter years of service: ");

    scanf("%d", &years);

 

    // Determine bonus percentage based on years of service

    if (years < 3) {

        bonus = salary * 0.05;

    }

    else if (years >= 3 && years <= 5) {

        bonus = salary * 0.10;

    }

    else if (years >= 6 && years <= 10) {

        bonus = salary * 0.15;

    }

    else {

        bonus = salary * 0.20;

    }

 

    // Calculate total pay

    totalPay = salary + bonus;

 

    // Output

    printf("\n----------------------------\n");

    printf("Employee Bonus Calculation\n");

    printf("----------------------------\n");

    printf("Basic Salary       : ₹ %.2f\n", salary);

    printf("Years of Service   : %d\n", years);

    printf("Bonus Amount       : ₹ %.2f\n", bonus);

    printf("Net Pay (with Bonus): ₹ %.2f\n", totalPay);

    printf("----------------------------\n");

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter basic salary: 50000
Enter years of service: 2

----------------------------
Employee Bonus Calculation
----------------------------
Basic Salary       : ₹ 50000.00
Years of Service   : 2
Bonus Amount       : ₹ 2500.00
Net Pay (with Bonus): ₹ 52500.00
----------------------------

OUTPUT 2 :
Enter basic salary: 60000
Enter years of service: 8

----------------------------
Employee Bonus Calculation
----------------------------
Basic Salary       : ₹ 60000.00
Years of Service   : 8
Bonus Amount       : ₹ 9000.00
Net Pay (with Bonus): ₹ 69000.00
----------------------------

OUTPUT 3 :

Enter basic salary: 45000
Enter years of service: 12

----------------------------
Employee Bonus Calculation
----------------------------
Basic Salary       : ₹ 45000.00
Years of Service   : 12
Bonus Amount       : ₹ 9000.00
Net Pay (with Bonus): ₹ 54000.00
----------------------------

Explanation

  1. The user enters the basic salary and years of service.
  2. The program decides the bonus percentage according to the given slab.
  3. bonus = salary × bonus_percentage.
  4. totalPay = salary + bonus.
  5. All details are displayed in a structured format.

Method 2:

C Program: Calculate bonus and apply tax deduction to get the Net Salary after Bonus and Tax

Introduction

In real-world payroll systems:

  1. Bonus is calculated based on years of service.
  2. Tax is deducted based on total income (salary + bonus).

Here’s a sample tax slab (can be modified):

Total Pay (Salary + Bonus)

Tax Rate

Up to ₹50,000

      0%

₹50,001 – ₹1,00,000

     10%

₹1,00,001 – ₹2,00,000

     20%

Above ₹2,00,000

     30%

 

C Program: Bonus & Tax Deduction Calculation

C

#include <stdio.h>

 

int main() {

    float salary, bonus, totalPay, tax, netPay;

    int years;

 

    // Input

    printf("Enter basic salary: ");

    scanf("%f", &salary);

    printf("Enter years of service: ");

    scanf("%d", &years);

 

    // 1. Bonus Calculation

    if (years < 3) {

        bonus = salary * 0.05;

    }

    else if (years >= 3 && years <= 5) {

        bonus = salary * 0.10;

    }

    else if (years >= 6 && years <= 10) {

        bonus = salary * 0.15;

    }

    else {

        bonus = salary * 0.20;

    }

 

    totalPay = salary + bonus;

 

    // 2. Tax Calculation (based on totalPay)

    if (totalPay <= 50000) {

        tax = 0;

    }

    else if (totalPay <= 100000) {

        tax = totalPay * 0.10;

    }

    else if (totalPay <= 200000) {

        tax = totalPay * 0.20;

    }

    else {

        tax = totalPay * 0.30;

    }

 

    // 3. Net Pay Calculation

    netPay = totalPay - tax;

 

    // 4. Display

    printf("\n--------------------------------------------\n");

    printf("        Employee Salary Slip (With Tax)     \n");

    printf("--------------------------------------------\n");

    printf("Basic Salary          : ₹ %.2f\n", salary);

    printf("Years of Service      : %d\n", years);

    printf("Bonus Amount          : ₹ %.2f\n", bonus);

    printf("Total Pay (Before Tax): ₹ %.2f\n", totalPay);

    printf("Tax Deduction         : ₹ %.2f\n", tax);

    printf("Net Pay (After Tax)   : ₹ %.2f\n", netPay);

    printf("--------------------------------------------\n");

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter basic salary: 40000
Enter years of service: 2

--------------------------------------------
        Employee Salary Slip (With Tax)     
--------------------------------------------
Basic Salary          : ₹ 40000.00
Years of Service      : 2
Bonus Amount          : ₹ 2000.00
Total Pay (Before Tax): ₹ 42000.00
Tax Deduction         : ₹ 0.00
Net Pay (After Tax)   : ₹ 42000.00
--------------------------------------------

OUTPUT 2 :
Enter basic salary: 80000
Enter years of service: 6

--------------------------------------------
        Employee Salary Slip (With Tax)     
--------------------------------------------
Basic Salary          : ₹ 80000.00
Years of Service      : 6
Bonus Amount          : ₹ 12000.00
Total Pay (Before Tax): ₹ 92000.00
Tax Deduction         : ₹ 9200.00
Net Pay (After Tax)   : ₹ 82800.00
--------------------------------------------

OUTPUT 3 :

Enter basic salary: 150000
Enter years of service: 12

--------------------------------------------
        Employee Salary Slip (With Tax)     
--------------------------------------------
Basic Salary          : ₹ 150000.00
Years of Service      : 12
Bonus Amount          : ₹ 30000.00
Total Pay (Before Tax): ₹ 180000.00
Tax Deduction         : ₹ 36000.00
Net Pay (After Tax)   : ₹ 144000.00
--------------------------------------------

Explanation

  1. Step 1: Bonus is calculated based on years of service.
  2. Step 2: Total pay = salary + bonus.
  3. Step 3: Tax rate is applied depending on total pay.
  4. Step 4: Net pay = total pay − tax.
  5. All details are displayed in a clean salary slip format.