Employee structure program

Posted: January 16, 2012 in Lab 1

There is a structure called employee that holds information like employee code, name date of joining. Write a program to create an array of structures and enter some data into it. Then ask the user to enter current date. Display the names of those employees whose tenure is 3 or more than 3 years according to the given current date.

#include<stdio.h>
int main()
{
	struct employee
	{
		char name[40];
		int code,doj,moj,yoj;

	};
	struct employee e[3];
	int i,d,m,y,yr;
      for(i=0;i<3;i++)
	{
		printf("Enter employee name & code\n");
		gets(e[i].name);
		scanf("%d",&e[i].code);
		printf("Enter date of joining dd/mm/yy\n");
		scanf("%d/%d/%d",&e[i].doj,&e[i].moj,&e[i].yoj);
		printf("Enter current date dd/mm/yy\n");
		scanf("%d/%d/%d",&d,&m,&y);
		//d=15; m=1; y=12;
		yr=y-e[i].yoj;
		if(yr>3)
		{
			printf("%s",e[i].name);
			continue;
		}
		if(yr==3)
			if(e[i].moj>m)
			{
				printf("%s",e[i].name);
				continue;
			}
		if(e[i].moj==m)
			if(e[i].doj>=d)
				printf("%s",e[i].name);
		}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s