Employee Payroll
C
Medium
2 views
Problem Description
Create structure of employee (id, name, basic_salary, allowances). Create a function calculateNetSalary() which will calculate the final salary by applying deductions (PF, tax).
Official Solution
#include <stdio.h>
// Employee structure
struct Employee {
int id;
char name[50];
float basic_salary;
float allowances;
};
// Function to calculate net salary
float calculateNetSalary(struct Employee e) {
float pf, tax, grossSalary, netSalary;
pf = 0.12 * e.basic_salary; // PF = 12% of basic
grossSalary = e.basic_salary + e.allowances;
tax = 0.10 * grossSalary; // Tax = 10% of gross
netSalary = grossSalary - (pf + tax);
return netSalary;
}
int main() {
struct Employee emp;
float netSalary;
// Input employee details
printf("Enter Employee ID: ");
scanf("%d", &emp.id);
printf("Enter Name: ");
scanf("%s", emp.name);
printf("Enter Basic Salary: ");
scanf("%f", &emp.basic_salary);
printf("Enter Allowances: ");
scanf("%f", &emp.allowances);
// Calculate net salary
netSalary = calculateNetSalary(emp);
// Display details
printf("n--- Employee Salary Details ---n");
printf("ID: %dn", emp.id);
printf("Name: %sn", emp.name);
printf("Net Salary: %.2fn", netSalary);
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!