| | |
C program to calculate number of days between 2 dates using structure of pointers....
![]() |
•
•
Join Date: May 2006
Posts: 4
Reputation:
Solved Threads: 0
C program to calculate number of days between 2 dates using structure of pointers....
0
#1 Nov 14th, 2007
/*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();
}
#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();
}
Re: C program to calculate number of days between 2 dates using structure of pointers....
0
#2 Nov 14th, 2007
First of all: please use codetags. It makes your code easier to read:
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:
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?
Niek
c Syntax (Toggle Plain Text)
#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:
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?
Niek
Last edited by niek_e; Nov 14th, 2007 at 6:07 am.
•
•
Join Date: May 2006
Posts: 4
Reputation:
Solved Threads: 0
Re: C program to calculate number of days between 2 dates using structure of pointers....
0
#3 Nov 14th, 2007
Re: C program to calculate number of days between 2 dates using structure of pointers....
0
#4 Nov 14th, 2007
•
•
Join Date: Nov 2007
Posts: 5
Reputation:
Solved Threads: 2
Re: C program to calculate number of days between 2 dates using structure of pointers....
0
#5 Nov 14th, 2007
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();
}
#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();
}
![]() |
Similar Threads
- array structs, size swap functions, the amount of days between to dates (C++)
- Program- calculate # of days between two days (C++)
- Difference between 2 dates by month (MS Access and FileMaker Pro)
- Having a little trouble with my Code. [please Help me out] (C++)
- Hello Everyone, I need Help with my C++ Code... (C++)
- Need help With this C++ Program..Confused.. (C++)
- Simple Time/Date Program (C)
Other Threads in the C Forum
- Previous Thread: Need help with expanding a unix path correctly.
- Next Thread: 16 bit to 8 bit
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






