An employee wants to provide bonus to its employees. Here are the requirements a
ID: 3816218 • Letter: A
Question
An employee wants to provide bonus to its employees. Here are the requirements and conditions Bonus is 10% of annual salary if performance is Good. Bonus is 5% of annual salary if performance is Average. No bonus if performance is Poor. You'll need to write a programmer defined function to calculate the bonus. The function will accept a double data-type for salary and an enum data-type for performance, and will return the calculated bonus to the main function. Prompt the use for salary and performance in the main function, and pass their values to your programmer defined function. You may have to provide your enum declaration global scope for your code to work. You'll have to add the bonus to the annual salary of the employee, and display the bonus and the total pay in the main function. If the user enters a wrong choice for enum, return -1, and display a suitable error message in your main function.Explanation / Answer
#include <stdio.h>
typedef enum {
Good = 1,
Average,
Poor
} grade;
double Bonus(double sal, grade g){
double b = 0;
if(g == Good)
b = sal*0.10;
else if(g == Average)
b = sal*0.05;
return b;
}
int main()
{
double salary = 0, total=0;
int g=0;
printf("Enter Salary: ");
scanf("%lf", &salary);
while(g<1 || g >3){
printf("Enter Grade (1-3): ");
scanf("%d", &g);
if(g<1 || g>3) printf("Invalid Grade. ");
}
total = salary + Bonus(salary, (grade)g);
printf("Total salary: %lf ", total);
return 0;
}
//---------------------------------------------------------------------------------------------------------------------------
sh-4.2$ gcc -o main *.c
sh-4.2$ main
Enter Salary: 12000
Enter Grade (1-3): 6
Invalid Grade. Enter Grade (1-3): 1
Total salary: 13200.000000
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.