# Program to Calculate Net Salary in C/C++

## Program to Calculate Net Salary in C/C++

This is a program to calculate net salary and display a salary slip of employer. It calculates HRA, PA, DA, PF & net salary from basic salary.

Q. Write a program in C and C++ to calculate net salary of an employee and display salary slip.

## 1. Program in C

``````#include<stdio.h>
int main() {
char str;
int no, bs;
float hra, da, ta, pf, net;
printf("\n Enter employee name: ");
scanf("%s", & str);
printf("\n Enter employee no.: ");
scanf("%d", & no);
printf("\n Enter basic salary: ");
scanf("%d", & bs);
hra = bs * 0.1;
da = bs * 0.08;
ta = bs * 0.05;
pf = bs * 0.02;
net = (bs + hra + da + ta) - pf;
system("cls");
printf("\n________________________________________________________________\n");
printf("\t\t\tSalary slip");
printf("\n________________________________________________________________\n");
printf("Emp. No: %ld\t\tName : %s", no, str);
printf("\n B.S\tHRA\tDA\tTA\tPF\n%d\t%f\t%f\t%f\t%f\n\n", bs, hra, da, ta, pf);
printf("Net salary=%f", net);
return 0;
}``````

## 2. Program in C++

``````#include<iostream>
using namespace std;
int main() {
char str;
int no, bs;
float hra, da, ta, pf, net;
cout << "\n Enter employee name: ";
cin >> str;
cout << "\n Enter employee no.: ";
cin >> no;
cout << "\n Enter basic salary: ";
cin >> bs;
hra = bs * 0.1;
da = bs * 0.08;
ta = bs * 0.05;
pf = bs * 0.02;
net = (bs + hra + da + ta) - pf;
system("cls");
cout << "\n________________________________________________________________\n";
cout << "\t\t\t" << "Salary slip";
cout << "\n________________________________________________________________\n";
cout << "Emp. No: " << no << "\t\tName : " << str;
cout << "\n B.S\tHRA\tDA\tTA\tPF\n" << bs << "\t" << hra << "\t" << da << "\t" << ta << "\t" << pf << "\n\n";
cout << "Net salary= " << net;
return 0;
}``````

## 4. Explanation-

As the main function starts we first declare some variables (str which is character array to store name, no & bs of integer type to store employee number and basic salary, hra, da, ta, pf, net of float type to store house rent allowance, dearness allowance, travveling allowance, profident fund and net salary respectively).

After that we ask user to put all the details. And then we calculate hra, da, ta and pf based on basic salary. Many a times the formula to calculate these things is given in the question or we can simply remember. After calculating we simply clear the output screen and print the salary slip. And that’s it program execution terminates.

### 5. Parts of program-

1. #include is a pre-processor directive. It is used to include header files.
2. stdio/iostream is header file which has certain commands that c/c++ supports. E.g. return, main, etc.
3. .h is an extension for header file.
4. int is data type. It indicates that the program returns a value.
5. main() is main function that indicates the compiler that the user written programs starts from here.
6. print/cout is the keyword use to print a message.
7. scanf/cin is the keyword use to store values in variables.
8. return statement is use to return a value. If any error occurs the program will return 0.

## Conclusion-

This was the program to calculate net salary and display salary slip in C/C++. We hope it was clear to you. If you find it useful then do share it with your programming buddies and friends. Also if you have any doubt regarding any post do tell us in the comment section.