Answer:
Written in C
#include <stdio.h>
int main(){
float salary,rate,raise,newsalary,totalsalary = 0.0 ,totalraise = 0.0 ,totalnewsalary = 0.0;
printf("Enter negative input to quit\n");
printf("Salary: ");
scanf("%f", &salary);
while(salary>=0){
if(salary>=0 && salary <30000){
rate = 0.07;
}
else if(salary>=30000 && salary <=40000){
rate = 0.055;
}
else{
rate = 0.04;
}
raise = rate * salary;
newsalary = salary + raise;
totalraise +=raise;
totalsalary+=salary;
totalnewsalary+=newsalary;
printf("Salary: %.2f\n", salary);
printf("Rate: %.2f\n", rate);
printf("Raise: %.2f\n", raise);
printf("New Salary: %.2f\n", newsalary);
printf("Salary: ");
scanf("%f", &salary);
}
printf("Total Salary: %.2f\n", totalsalary);
printf("Total New Salary: %.2f\n", totalnewsalary);
printf("Total Raise: %.2f\n", totalraise);
return 0;
}
Explanation:
The declares all necessary variables as float
float salary,rate,raise,newsalary,totalsalary = 0.0 ,totalraise = 0.0 ,totalnewsalary = 0.0;
This tells the user how to quit the program
printf("Enter negative input to quit\n");
This prompts user for salary
printf("Salary: ");
This gets user input
scanf("%f", &salary);
The following iteration is repeated until user enters a negative input
while(salary>=0){
This following if conditions check for range of salary and gets the appropriate rate of salary raise
<em> if(salary>=0 && salary <30000){</em>
<em> rate = 0.07;</em>
<em> }</em>
<em> else if(salary>=30000 && salary <=40000){</em>
<em> rate = 0.055;</em>
<em> }</em>
<em> else{</em>
<em> rate = 0.04;</em>
<em> } </em>
This calculates the raise by multiplying the salary by the rate of increment
raise = rate * salary;
This calculates the new salary
newsalary = salary + raise;
This calculates the total raise
totalraise +=raise;
This calculates the total salary
totalsalary+=salary;
This calculates the total new salary
totalnewsalary+=newsalary;
This prints the salary
printf("Salary: %.2f\n", salary);
This prints the rate of increment
printf("Rate: %.2f\n", rate);
This prints the raise in salary
printf("Raise: %.2f\n", raise);
This prints the new salary
printf("New Salary: %.2f\n", newsalary);
This prompts user for salary input
printf("Salary: ");
This gets user input for salary
scanf("%f", &salary);
} The while loop ends here
This prints the total salary
printf("Total Salary: %.2f\n", totalsalary);
This prints the total new salary
printf("Total New Salary: %.2f\n", totalnewsalary);
This prints the total raise in salary
printf("Total Raise: %.2f\n", totalraise);
return 0;