C/array
Expert: Abhishek Kumar - 11/17/2011
Questioni would very much appreciate it if i could get a response from you today. i am new to this site and i really hope you can help me.
i just started learning about arrays i think i know the basic basic eg. how to declre it but not sure where to put it in my algorithm.
i should have 36 employees and i need to print all their gross salary; i should also calculate their deduction from taxes and net salary and print it as well.... i dont know how to print that much information at once.. but i do understand that i should use array to do it problem is i dont know how to do arrays. help plz this is what i have so far....
start
declare
total_deduction,Grss_sal,Net_sal as real
EmpID,post,health_Inst,Nme as string
intiger numGrss_sal [10]
real countE [10]
Grss_sal= 0.0
Net_Sal=0.0
total_deductions= 0.03
print "this program should return a each employee's Gross salary, total deductins and net salary after the user enter employee's information. There should be a total of 36 employees."
for countE=1 to 36 Do
print"please enter Employee's ID."
Read EmpID
Print"enter the name"
read Nme
print"enter the assigned health institution."
read health_Inst
print"enter position."
read post
print"Enter their Gross Sal."
read Grss_Salry
if Grss_Salry > 30000 then
total_deductions= total_deductions+(0.15*Grss_Salry)
else
total_deductions= total_deductions+(0.08*Grss_salary)
if Grss_salary >= 25000 then
total_deductions= total_deductions+(0.05*Grss_salary)
else
total_deductions=total_deductions+(0.04*Grss_salary)
endif
endif
Net_Salry= Net_Salry+ total_deductions
Print "Gross salary is",Grss_Salary
Print "The total deduction is ",total_deductions
Print "The net salary is",Net_salary
endfor
print "press enter to exit the program."
stop
AnswerHi Roxybeu,
I have written code for you but from next time i want you to at least try before asking. And for this case you need to read about structures also.
#include<stdio.h>
#define EMP_NUM 36
struct employ {
char name[100];
char EmpID[20];
char health_Ins[20];
char post[20];
float Net_sal;
float Grss_sal;
float total_deduction;
} emp[EMP_NUM];
float get_tot_deduction(float gross_salary, float total_deductions) {
if (gross_salary > 30000)
total_deductions= total_deductions+(0.15*gross_salary);
else if( gross_salary <= 30000 && gross_salary > 25000)
total_deductions= total_deductions+(0.08*gross_salary);
else if (gross_salary <= 25000 && gross_salary > 25000)
total_deductions= total_deductions+(0.05*gross_salary);
else
total_deductions=total_deductions+(0.04*gross_salary);
return total_deductions;
}
int main()
{
int i=0, brk;
char id[20];
for(i=0;i<EMP_NUM;i++) {
printf("\n(%d)Please enter Employee's ID: ", i+1);
scanf("%s", emp[i].EmpID);
printf("\nEnter the name: ");
scanf("%s", emp[i].name);
printf("\nEnter position: ");
scanf("%s", emp[i].post);
printf("\nEnter Health Insurance: ");
scanf("%s", emp[i].health_Ins);
printf("\nEnter their Gross Sal: ");
scanf("%f", &emp[i].Grss_sal);
emp[i].total_deduction=get_tot_deduction( emp[i].Grss_sal, 0.3);
emp[i].Net_sal= emp[i].Grss_sal - emp[i].total_deduction;
}
do{
printf("\nEnter Employee's ID, whose info you want: ");
scanf("%s", id);
for(i=0;i<EMP_NUM;i++) {
if(!(strcmp(id, emp[i].EmpID)))
break;
}
if(i==EMP_NUM) {
printf("\nNo Employ with this ID exist.\n");
goto carryon;
}
printf("\n\n\n==== Printing Info of the Employ you requested=====\n\n\n");
printf("Employee's ID=%s\n", emp[i].EmpID);
printf("Name =%s\n", emp[i].name);
printf("Position =%s\n", emp[i].post);
printf("Health Insurance =%s\n", emp[i].health_Ins);
printf("Gross Sal=%f.\n", emp[i].Grss_sal);
printf("TOT Deduction=%f.\n", emp[i].total_deduction);
printf("Net Salary=%f.\n", emp[i].Net_sal);
carryon:
printf("\nPress 1 to Exit or any other number to continue with the search\n");
scanf("%d", &brk);
if(brk==1)
break;
} while(1);
printf("\nThank you for using our system.\n");
return 0;
}
Regards,
Abhishek Kumar