Question: C programming..... I ned total_sal, total_ras, and total_new to work They should be totals of all the salary, raises, and new salary #include #include #include
C programming..... I ned total_sal, total_ras, and total_new to work
They should be totals of all the salary, raises, and new salary
#include
struct employee { char name[50]; float salary; float rate; float raise; float new_salary; };
int main(){ int i,j,n; char name[50]; float salary; float rate; float raise; float new_salary; float total_sal,total_ras,total_new;
struct employee **emp = ( struct employee ** )malloc( 7 * sizeof( struct employee * ) );
for( i = 0 ; i < 7 ; i++ ) emp[i] = ( struct employee * )malloc( 7 * sizeof( struct employee ) );
for( i = 0 ; i < 7 ; i++ ){ printf("Enter name : "); scanf("%s",name); memcpy(emp[i]->name,name,20); printf("%s ", emp[i]->name); printf("Enter salary : "); scanf("%f", &salary); emp[i]->salary=salary; //total_sal=total_sal+salary;
if(salary>=0 && salary<=29999){ emp[i]->rate=7; emp[i]->raise=(salary/100*7); emp[i]->new_salary=salary+(salary/100*7); } if(salary>=30000 && salary<=40000){ emp[i]->rate=5.5; emp[i]->raise=(salary/100*5.5); emp[i]->new_salary=salary+(salary/100*5.5); } if(salary>40000){ emp[i]->rate=4; emp[i]->raise=(salary/100*4); emp[i]->new_salary=salary+(salary/100*4); }}
if( i < 6 ) gets( emp[i]->name );
for(i=0; i<7; i++) { for(j=i+1; j<7; j++) { if(strcmp(emp[i]->name, emp[j]->name)>0) { emp[n] = emp[i]; emp[i] = emp[j]; emp[j] = emp[n]; }}}
printf(" NAME \t\tSALARY \t\tRATE %%\t\tRAISE\t\tNEW SALARY "); for( i = 0 ; i < 7 ; i++ ){ printf("%s \t\t%.2f \t%.3f \t\t%.2f \t\t%.2f ",emp[i]->name,emp[i]->salary,emp[i]->rate,emp[i]->raise,emp[i]->new_salary); } printf(" TOTAL \t\t%.2f\t\t\t%.2f\t%.2f",total_sal,total_ras,total_new);
FILE *f; f=fopen("c:\\program5.txt","w"); fprintf(f," NAME \t\tSALARY \t\t\tRATE %%\t\tRAISE\t\tNEW SALARY "); for( i = 0 ; i < 7 ; i++ ){ fprintf(f,"%d %s \t\t%.2f \t%.3f \t\t%.2f \t%.2f ",i,emp[i]->name,emp[i]->salary,emp[i]->rate,emp[i]->raise,emp[i]->new_salary); } // fprintf(f," TOTAL \t\t%.2f\t\t\t\t%.2f\t\t%.2f",total_sal,total_ras,total_new); fclose(f);
FILE *g; g=fopen("c:\\student.bin","wb"); fwrite(&emp,sizeof (struct employee),7,g); fclose(g);
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
