A company gives a bonus to all its employees A 2 bonus on sa
Solution
#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



