/*This program is going infinite.PLS help*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f,flag=0;
printf("Enter first date");
scanf("%d%d%d",&a,&b,&c);
printf("Enter second date");
scanf("%d%d%d",&d,&e,&f);
const int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
while(c!=f||b!=e||a!=d)

{
	a++;
	if((b==4)||(b==6)||(b==9)||(b==11))
		f=30;
	else if(b==2)
	{
		if(d%4==0)
			f=29;
		else
			f=28;
	}
	else
		f=31;
	if(a>f)
	{
		b++;
		a=1;
	}
	if(b==13)
	{
		c++;
		b=1;
	}
	flag++;

}
	printf("%d",flag);
	getch();
}

Recommended Answers

All 7 Replies

First of all: please use codetags. It makes your code easier to read:

#include<stdio.h>

int main()
{
	int a,b,c,d,e,f,flag=0;
	printf("Enter first date");
	scanf("%d%d%d",&a,&b,&c);
	printf("Enter second date");
	scanf("%d%d%d",&d,&e,&f);
	const int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	while(c!=f||b!=e||a!=d)

	{
		a++;
		if((b==4)||(b==6)||(b==9)||(b==11))
			f=30;
		else if(b==2)
		{
			if(d%4==0)
				f=29;
			else
				f=28;
		}
		else
			f=31;
		if(a>f)
		{
			b++;
			a=1;
		}
		if(b==13)
		{
			c++;
			b=1;
		}
		flag++;

	}
	printf("%d",flag);
	getchar();
}

I've replaced getch with getchar. void main with int main and removed conio. This makes your code standard for all compilers.
You might also want to use some usefull names for your vars. A,b,c, etc is not very practical.

Now for your problem:

while(c!=f||b!=e||a!=d)

{
a++;

What happens if a > d ? -> It becomes a while(1) loop. And that's just 1 problem of the many. What is this code supposed to do?

Suppose a>d.
But the problem is while loop is infinite even if a<d

What is this code supposed to do?

Still don't know

hey i also solved in he same manner

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f,flag=0;
printf("Enter first date");
scanf("%d%d%d",&a,&b,&c);
printf("Enter second date");
scanf("%d%d%d",&d,&e,&f);
const int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
while(c!=f||b!=e||a!=d)

{
a++;
if((b==4)||(b==6)||(b==9)||(b==11))
f=30;
else if(b==2)
{
if(d%4==0)
f=29;
else
f=28;
}
else
f=31;
if(a>f)
{
b++;
a=1;
}
if(b==13)
{
c++;
b=1;
}
flag++;

}
printf("%d",flag);
getch();
}

whenever u use like this (c!=f||b!=e||a!=d) if checks only c!=f won't go for remaing part which is always 1 which results infinite loop...
want more??? my id [email snipped]

Any one can explain the logic .... I am not able to understand the logic....

Use this Code For C

int DifferentDate{ int d1,int m1, int y1, int d2, int m2,int y2)



m1 = (m1 + 9) MOD 12;
y1 = y1 - m1 / 10;
x1= 365*y1 + y1/4 - y1/100 + y1/400 + (m1*306 + 5)/10 + ( d1 - 1 );

m2 = (m2 + 9) MOD 12;
y2 = y2 - m2 / 10;
x2= 365*y2 + y2/4 - y2/100 + y2/400 + (m2*306 + 5)/10 + ( d2 - 1 );

return X2 - X1;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.