A company gives a bonus to all its employees. A 2% bonus on salary is given to e
ID: 3789042 • Letter: A
Question
A company gives a bonus to all its employees. A 2% bonus on salary is given to employees who have been with the company for at least 2 years and less than 5 years. A 5% bonus on salary is given to employees who have been with the company at least 5 years, but less than 10 years. A 10% bonus is given to employees who have been with the company more than 10 years. Write a program to enter the annual salary and length of employment for an employee. Display the employee's annual salary, bonus, and total amount paid to employee. Show 2 decimal places. codeblocksplease !!!!!!!! Error Checking - Your program must terminate for any of the following: Annual salary is a negative number Years of service ate less than zero Codeblocks please !!!!!! Years of service are greater than 50. Before terminating the program should display an appropriate error message. Use a return statement to end the program early, For example, return -1;Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
//Validates the service
int validateService(int service)
{
//Service cannot be negative
if(service < 0)
{
printf(" ERROR: Years of service cannot be negative");
return -1;
}
//Service cannot be greater than 50
if(service > 50)
{
printf(" ERROR: Years of service cannot be greater than 50");
return -1;
}
}
//Validates salary
int validateSalary(float salary)
{
//Salary cannot be negative
if(salary < 0)
{
printf(" ERROR: Annual salary cannot be negative");
return -1;
}
}
//Bonus calculation
int bonousCalculation(int service, float salary)
{
float bonus;
//Service greater than equal to 2 and less than 5
if(service >= 2 && service < 5)
bonus = 2;
//Service greater than equal to 5 and less than 10
else if(service >= 5 && service < 10)
bonus = 5;
//Service greater than 10
else
bonus = 10;3
//returns the bonus
return bonus;
}
void main()
{
//Variable declaration to store employee information
char name[20];
int service;
float salary, bonus, totalAmt;
//Accepts employee data
printf(" Enter Employee Name: ");
gets(name);
printf(" Enter Employee Monthly Salary: ");
scanf("%f", &salary);
//Checks for the salary validation. If return result is -1 i.e., invalid exit the program
if(validateSalary(salary) == -1)
exit(0);
printf(" Enter Employee Years Of Service: ");
scanf("%d", &service);
//Checks for the service validation. If return result is -1 i.e., invalid exit the program
if(validateService(service) == -1)
exit(0);
//Calculate the bonus by calling the bonusCalculation function
bonus = bonousCalculation(service, salary);
//Calculates the total amount
totalAmt = salary + (salary * (bonus / 100));
//Displays Employee information
printf(" Employee Name: %s", name);
printf(" Employee Salary: %.2f: ", salary);
printf(" Employee bonus: %.2f", bonus);
printf(" Employee Total Amount: %.2f", totalAmt);
}
Sample run 1:
Enter Employee Name: Mohan
Enter Employee Monthly Salary: -3
ERROR: Annual salary cannot be negative
Sample run 2:
Enter Employee Name: Pyari
Enter Employee Monthly Salary: 1000
Enter Employee Years Of Service: -5
ERROR: Years of service cannot be negative
Sample run 3:
Enter Employee Name: Pyari
Enter Employee Monthly Salary: 1000
Enter Employee Years Of Service: 52
ERROR: Years of service cannot be greater than 50
Sample run 4:
Enter Employee Name: Pyari
Enter Employee Monthly Salary: 1000
Enter Employee Years Of Service: 12
Employee Name: Pyari
Employee Salary: 1000.00:
Employee bonus: 10.00
Employee Total Amount: 1100.00
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.