#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { int average_salary=0,i,counter; struct employee { char name[50]; int salary; }; struct employee * factory = NULL; int workers=0; printf("Enter the name of your employee and enter his salary, !end to stop\n"); while(true) { i=0; factory=(struct employee *)realloc(factory,(++workers)*sizeof(struct employee)); scanf("%s",factory[workers-1].name); if(strcmp(factory[workers-1].name,"!end")==0) { printf("END!!!\n"); factory=(struct employee *)realloc(factory,(--workers)*sizeof(struct employee)); break; } scanf("%d",&factory[workers-1].salary); }; if(workers==0) exit(-1); for(counter=0;counter<workers;counter++) average_salary+=factory[counter].salary; average_salary/=workers; printf("Average salary on your factory %d\n",average_salary); for(counter=0;counter<workers;counter++){ printf("%s Your salary is ",factory[counter].name); if (average_salary>factory[counter].salary) printf("%d below average\n",average_salary-factory[counter].salary); else if (average_salary<factory[counter].salary) printf("%d above average\n",factory[counter].salary-average_salary); else printf("exactly the average\n"); } free(factory); system("PAUSE"); return 0; } |