Question
**C programming I would like to struct array string sort the names in my structure;however, I am getting some error and I am not really
**C programming I would like to struct array string sort the names in my structure;however, I am getting some error and I am not really sure why, any help would be appreciated**
#include
struct salary { char name[6][15]; char t[15]; float sal,newsal; float rate; float raise; };
void load(struct salary s[], int n, float *totsal); void rateandraise(struct salary s[], int n, float *totraise); void newsalary(struct salary s[], int n, float *totnewsal); void print(struct salary s[], int n, float totsal, float totraise, float totnewsal);
void main() { float totsal,totraise,totnewsal;
struct salary s[size]; load(s,size,&totsal); rateandraise(s,size,&totraise); newsalary(s,size,&totnewsal); print(s,size ,totsal,totraise,totnewsal); sort(s, size);
}
void load(struct salary s[], int n, float *totsal) { int i;
for(i=0;i printf("Enter their respective salary: "); scanf("%f",&s[i].sal); *totsal+=s[i].sal; fflush(stdin); printf(" "); printf(" "); } } void rateandraise(struct salary s[], int n, float *totraise) { int i; for(i=0;i if(s[i].sal>0 && s[i].sal<30000) s[i].rate=7.0; else if(s[i].sal>=30000 && s[i].sal<=40000) s[i].rate=5.5; else if(s[i].sal>40000) s[i].rate=4.0; else s[i].rate=0; s[i].raise=((s[i].sal*s[i].rate)/100); *totraise+=s[i].raise; } } void newsalary(struct salary s[], int n, float *totnewsal) { int i; for(i=0;i *totnewsal+=s[i].newsal; } } void print(struct salary s[], int n, float totsal, float totraise, float totnewsal) { int i; printf(" "); printf(" Name Salary Rate Raise New salary"); printf(" "); for(i=0;i printf(" %s %9.2f %5.2f %8.2f %9.2f ",s[i].name,s[i].sal,s[i].rate,s[i].raise,s[i].newsal); printf(" "); } printf(" "); printf(" "); printf("total: %9.2f %8.2f %9.2f", totsal,totraise, totnewsal); } void sort(struct salary s[], int n) { int i,j; struct salary t; for(i=0;i<4;i++) for(j=0;j<4;j++) if(strcmp(s[j].name[j],s[j+1].name[j+1])>0) { strcpy(t,s[j].name[j]); strcpy(s[j].name[j],s[j+1].name[j+1]); strcpy(s[j+1].name[j+1],t); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started