Haven't done pointers yet.... So I'm supposed to do the program w/out them. TIA.
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct employees
{
int salary;
char firstname[40];
char lastname[40];
char departmentname[40];
} employee[50];
/* struct departments
{
int department_number;
char department_name;
} department; */
void main()
{
int x, y, z;
int nmbrofdeps;
int nmbrofeps;
int tmp, strtmp;
int op1, op2;
char dprtmnt_in[40];
void high_val(struct employees emp_data);
//employee[0].salary=0;
//employee[0].firstname='df';
//employee[0].lastname='df';
//employee[0].departmentname='df';
printf("Please enter the following data.");
printf("\nHow many employees' data would you like to enter?");
scanf("%d", &nmbrofeps);
for(x=1; x<=nmbrofeps; x++)
{
printf("\nEnter Employee's First Name : ");
scanf("%s", &employee[x].firstname);
printf("\nEnter Employee's Last Name : ");
scanf("%s", &employee[x].lastname);
printf("\nEnter Employee's Salary : ");
scanf("%d", &employee[x].salary);
printf("\nEnter Employee's Department Name : ");
scanf("%s", &employee[x].departmentname);
}
menustart: clrscr();
printf("\n\n\t\t########Options########");
printf("\n\t\t1 - See Employee listing under a Department.");
printf("\n\t\t2 - Find Employee with the highest salary in a Department.");
printf("\n\t\t3 - Find Employee with the highest salary from all Departments.");
printf("\n\t\t4 - Exit Program.");
optionreset:
printf("\n\n\n\nEnter your choice here: ");
scanf("%d", &op1);
switch(op1)
{
case 1: break;
case 2: goto hds;
case 3: goto hs;
case 4: goto end;
default: printf("Only enter a number from the options please.");
goto menustart;
}
clrscr();
printf("\n\nType a department name to list all of it's employees.");
printf("\nHere are the department names you have inputted.");
for(y=1; y<=nmbrofeps; y++)
{
printf("\n%s", employee[y].departmentname);
}
printf("\n\n\n");
scanf("%s", &dprtmnt_in);
for(z=1; z<=nmbrofeps; z++)
{
strtmp=strcmp(employee[z].departmentname, dprtmnt_in);
if(strtmp==0)
{
printf("\n\n");
printf("\nEmployee's First Name : %s", employee[z].firstname);
printf("\nEmployee's Last Name : %s", employee[z].lastname);
printf("\nEmployee's Salary : %d", employee[z].salary);
printf("\nEmployee's Department : %s", employee[z].departmentname);
printf("\n\n");
getch();
goto menustart;
}
if(strtmp!=0)
{
printf("\nNo such Department exists.");
goto menustart;
}
}
hds: high_val(employee);
hs:
end:
getch();
}
void high_val(struct employees emp_data)
// high val function //
Yeah, a LOT of tabs... but I use this program that inputs them for no real reason... sorry for that. TIa.