# C++ | Bonus in salary

Introduction

This is tutorial in c++ to calculate bonus on salary. The bonus percentage is decided according to gender of the person. Then the salary is calculated. The first program shows only the bonus. The next program shows bonus as well as total salary after addition of bonus. You can extend the program by your own bonus system. Go enjoy the program. Lets begin…………

Program to calculate bonus on salary.

``````
#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type int and char.
int a,b;
char c;
//Input salary and gender save them in 'a' and 'c'
cout<<"Enter the salary"<<endl;
cin>>a;
cout<<"Enter the gender"<<endl;
cin>>c;
//calculate bonus and save it in 'b'
//and print bonus
if(c=='f')
{
b=(a*10)/100;
cout<<"Bonus applicable "<<b;
}
else
{
if(c=='m')
{
b=(a*5)/100;
cout<<"Bonus applicable "<<b;
}
else
cout<<"Invalid gender"<<endl;
}
//get character
getch();
}
``````

Output

Enter the salary
1000
Enter the gender
m
Bonus applicable 50.

Program to calculate bonus and show total salary.

``````
#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type int and char
int a,b;
char c;
//Input salary and gender save them in 'a' and 'c'
cout<<"Enter the salary"<<endl;
cin>>a;
cout<<"Enter the gender"<<endl;
cin>>c;
//calculate bonus and save it in 'b'
if(c=='f')
b=(a*10)/100;
else
{
if(c=='m')
b=(a*5)/100;
else
c='i';
}
if(c=='i')
cout<<"Invalid gender";
else
{
cout<<"Bonus applicable "<<b<<endl;
b=b+a;
cout<<"Total salary "<<b;
}
//get character
getch();
}
``````

Output

Enter the salary
10000
Enter the gender
f
Bonus applicable 500
Total salary 10500

How does it work

1. You enter the salary of the person.
2. You enter the gender of the person.
3. The bonus percentage is decided accordingly.
4. The bonus is added to total salary.
5. The bonus and total salary is printed.

Extending it

The program can be extended by using your own bonus system. For example, you can decide the bonus percentage according to salary amount. Go ahead and extend it…

Explanation.

1. Include ‘iostream.h’ and ‘conio.h’ files.
3. Start program by first clearing the screen.
4. Declare the variables as int and char (name them as you want.)
5. Add cout and cin of variable of input of salary and gender.(as shown in program)
6. Decide the bonus by using if-else conditional statement.
7. Calculate the bonus.
8. Calculate the total salary.
9. Print the bonus and total salary.

At the end

You learnt creating the c++ program of bonus on salary according to gender of person. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Sharing options: