Question: Write a C program to calculate salary raise for employees. I need to know whats wrong with this code because it does not compile. #include
Write a C program to calculate salary raise for employees. I need to know whats wrong with this code because it does not compile.
#include
struct employ { char name [20]; float salary, rate, raise, newsalary; };
void load(struct employ e[],int n) { int t; for (t = 0; t fflush(stdin); } } void sort(struct employ e[], int n) { struct employ t; int t,s; for (t = 0; t void checkrate(struct employ e[], int n) { int t; for (t = 0; t< n; t++) { if (e[t].salary> 40000) e[t].rate = 4.00; else if (e[t].sal >= 30000 && e[t].sal <= 40000) e[t].rate = 5.50; else if (e[i].salary< 30000 && e[i].salary> 0) e[i].rate = 7.00; } } void calculateraise(struct employ e[], int n) { int t; for (t = 0; t< n; t++) { if (e[t].sal > 40000) e[t].raise = .04* e[i].salary; else if (e[t].salary>= 30000 && e[t].salary <= 40000) e[t].raise = .055 * e[t].salary; else if (e[t].salary < 30000 && e[t].salary> 0) e[t].raise =.07 * e[t].salary; } } void calculatenewsalary(struct employ e[], int n) { int t; for (t = 0; t< n; t++){ e[t].newsalary = e[t].salary + e[t].raise; } } void savetext (struct employ e[], int n) { int t; FILE *f; f = fopen ("C:\\employ.txt", "w"); for (t = 0; t fprintf(f,"%S %f %f %f %f ",e[t].name,e[t].salary,e[t].rate,e[t].raise,e[t].newsalary); } fclose(f); } void gettext (struct employ e[], int n) { FILE *f; int length, t; f = fopen("C:\\employ.txt", "r"); for (t = 0; t void getbin (struct employ e[], int n) { FILE *f; f = fopen ("C:\\employ.txt", "rb"); fread(&e,sizeof(e[0]),n,f); fclose(f); } void print(struct employ e [], int n) { int t; float totalsalary = 0, totalaise = 0, newsalary = 0; for (i = 0; i void main() { int n; printf("Enter the number of employees: "); scanf(%d",&n); fflush(stdin); struct employ e[n]; load(e,n); sort(e,n); checkrate(e,n); calculateraise(e,n); calcualtenewsalary(e,n); print(e,n); savetext(e,n); gettext(e,n); savebin(e,n); getbin(e,n); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
