Question:
Write a C program to calculate salary raise for employees.
If salary is between $0 < $30000 the rate is 7.0%
If salary is between $30000 <= $40000 the rate is 5.5%
If salary is greater than $40000 the rate is 4.0%
Answer:
#include <stdio.h>
int main() {
float salary;
printf("Salary: ");
scanf("%f", &salary);
float rate = 0.00;
if (salary >=0 && salary <=30000) {
rate = 0.07;
}
else if(salary <=40000){
rate = 0.055;
}
else {
rate = 0.04;
}
salary = salary * rate;
printf("Salary Raise: ");
printf("%.2f", salary);
return 0;
}
Step-by-step explanation:
This line declares the salary as float
float salary;
This line prompts user for salary input
printf("Salary: ");
This line gets user input
scanf("%f", &salary);
This line declares and initializes rate to 0.00
float rate = 0.00;
The following condition determines rate for salary between 0 and 30000
if (salary >=0 && salary <=30000) {
rate = 0.07;
}
The following condition determines rate for salary between 30001 and 40000
else if(salary <=40000){
rate = 0.055;
}
The following condition determines rate for salary greater than 40000
else {
rate = 0.04;
}
This calculates the raise in salary
salary = salary * rate;
The next two lines prints the salary raise
printf("Salary Raise: ");
printf("%.2f", salary);