c0c0pIe

3 years ago

6. Suppose a company decides to raise the salaries of its employees according to the following table:
employee_status years_of_service percent_raise
Full-time Less than 5 years 4.0
Full-time 5 years or more 5.0
Part-time Less than 5 years 2.5
Part-time 5 years or more 3.0
If employee_status value is ‘F’, the employee is Full-time; if it is ‘P’, he or she is a part-timer. Write this program that computes the new salary of an employee given his or her employee_status, year_of_service and salary by the users.
Input validation: Do not accept a negative value for the number of years_of_service,

This is because if the computer divides 5/100 it gives 0 as both numerator and denominator are integer type. If you make it 0.05 which is a float type it upgrades all other variables to the float type...

/*******************************************************************************
Suppose a company decides to raise the salaries of its employees according to the following table:
employee_status years_of_service percent_raise
Full-time Less than 5 years 4.0
Full-time 5 years or more 5.0
Part-time Less than 5 years 2.5
Part-time 5 years or more 3.0
If employee_status value is ‘F’, the employee is Full-time; if it is ‘P’, he or she is a part-timer. Write this program that computes the new salary of an employee given his or her employee_status, year_of_service and salary by the users.
Input validation: Do not accept a negative value for the number of years_of_service,
*************************************************************************/
#include<stdio.h>
#include<conio.h> /*For better view*/
#include<stdlib.h> /*For exit function*/
int main()
{
char time=0;
int yrs=0;
float sal=0,nsal=0;
printf("Welcome,do tou work full time(f) or part time(p): ");
scanf("%ch",&time);
printf("For how many years have you been working here?: ");
scanf("%d",&yrs);
printf("What you they pay you?(per month): RM");
scanf("%f",&sal);
/*Nested if for new salary*/
if(time=='f'&&yrs>5)
{
nsal=sal*0.05;
nsal+=sal;
}
else if(time=='f'&&yrs<=5)
{
nsal=sal*0.04;
nsal+=sal;
}
else if(time=='p'&&yrs>5)
{
nsal=sal*0.03;
nsal+=sal;
}
else if(time=='p'&&yrs<=5)
{
nsal=sal*0.025;
nsal+=sal;
}
else
{
printf("Something went wrong!!!Please check your output."); /*If input is no a number*/
exit(0);
}
printf("Your new salary is:RM %f",nsal); /*Change %f to %d if want an output in round figure*/
getch();
return 0;
}