In this tutorial, we will learn how to write a program that calculate gross salary of an employe.
A company decides to give bonus to all its employees on new year. A 5% bonus on salary is given to male workers and 10% bonus on salary is given to female workers.This is a C program to enter the salary and gender of the employees. If the salary of the employee is less than 10000, then the employee gets an extra 2% bonus on salary. Calculate the bonus that has to be given to the employee and display the salary that the employee will get.
A company decides to give bonus to all its employees on new year. A 5% bonus on salary is given to male workers and 10% bonus on salary is given to female workers.This is a C program to enter the salary and gender of the employees. If the salary of the employee is less than 10000, then the employee gets an extra 2% bonus on salary. Calculate the bonus that has to be given to the employee and display the salary that the employee will get.
Example:-
Input salary = 9500
Bonus = 665
Gross salary = 10165
Bonus = 665
Gross salary = 10165
Solution:-
- In this program we will use one extra header file <string.h> for enter string value as ( M ) and ( F ).
- We will use there variables salary,bonus and gender in this program.
- Use two data types float and char for floating point value and string.
- Use some if else statementin this program as -
{
if(salary>10000)
bonus=(float)(salary*0.05);//0.05--5%
else
bonus=(float)(salary*0.07);
}
- Use some logics to calculate the bonus and gross salery as -
bonus=(float)(salary*0.1);
- Print bonus and gross salary of an employe.
C program code
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
float salary,bonus;
char gender;
printf("\n Enter M for Male and F for Female\n ");
scanf("%c",&gender);
printf(" Enter Salary\n ");
scanf("%f",&salary);
if(gender=='M' || gender=='m')
{
if(salary>10000)
bonus=(float)(salary*0.05);//0.05--5%
else
bonus=(float)(salary*0.07);
}
if(gender=='F' || gender=='f')
{
if(salary>10000)
bonus=(float)(salary*0.1);//0.1--10%
else
bonus=(float)(salary*0.12);
}
salary+=bonus;
printf("\n Bonus=%.2f\n Salary=%.2f\n",bonus,salary);
getch();
}
OUTPUT 1:
OUTPUT 2:
In first output,the gender is ( M ) and the value of salery is 9500
After calculation
The bonus is 665
And the salary is 10165
9500 + 665 = 10165
After calculation
The bonus is 1550
And the salary is 17050
15500 + 1550 = 17050
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.
Created by-- HARSH CHAUHAN
No comments:
Post a Comment