At the end of a financial year a company decided to give bonus for their employees. The bonus for each employee is calculated as n times of their basic salary. n is a number between 0 and 2.
You are asked to write a C program to calculate the bonus given for the employees.
Write a function called calcNoOfTimes() to calculate and return the number of times for each employee. Number of times depend on the employee category as shown in the following table.
Employee Category No of times
1 1.0
2 1.5
Other ( 3 - 9) 2.0
In your main function enter the employee category and the salary of an employee from the keyboard. Calculate and display the bonus given for the employee using the above implemented functions.
Enter Salary : 15000.00
Enter employee number : 2
Bonus : 22500.00
#include<iostream>
using namespace std;
void calcNoOfTimes()
{
int n,sal;
double bonus;
cout<<"Enter the basic salary: ";
cin>>sal;
cout<<"Enter the employee number: ";
cin>>n;
if(n==1){
bonus=1.0*sal;
cout<<"Bonus is: "<<bonus;
}
else if(n==2){
bonus=1.5*sal;
cout<<"Bonus is: "<<bonus;
}
else if(n>=3 && n<=9){
bonus=2.0*sal;
cout<<"Bonus is: "<<bonus;}
else{
cout<<"Invalid employee number";
}
}
int main()
{
calcNoOfTimes();
return 0;
}
Comments
Leave a comment