>Do you have a specific problem with this
Yes, it doesn't work. Sadly, google doesn't help a great deal with the art of debugging code.
>im having problems calculating the number of days until the 25/12/2002
You're making this very hard on yourself, remember to keep programs and solutions as simple as possible or you'll get stuck on annoying details that cause trouble. This works.
Code:
#include <stdio.h>
struct dat{
int day;
int month;
int year;
};
int main ( void )
{
char loop ='y';
while (loop == 'y'||loop == 'Y') {
int leap, i, day = 0, total;
struct dat t;
const int daytab[2] [13] = {
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};
printf("***************************\n");
printf("*A DATE CALCULATOR PROGRAM*\n");
printf("***************************\n\n");
printf("Please enter a date from which you wish to calculate\n");
printf("how many days until the 25/12/2002.\n\n");
scanf("%d/%d/%d", &t.day,&t.month,&t.year);
leap = ( t.year % 4 == 0 && t.year % 100 != 0 || t.year % 400 == 0 );
/* Rethink your error handling, it could be
** implemented better and more accurately.
*/
for (i = 1; i < t.month; i++)
day += daytab[leap][i];
day += t.day;
if ( leap == 0 )
total = 359 - day;
else
total = 360 - day;
printf("%d %s until 25/12/2002\n\n", total, (total == 1)?"day":"days");
printf("Would you like to enter another date? (Y/N)\n");
scanf("\n%c",&loop);
}
return 0;
}
However, it only works for the year 2002. You apparently haven't gotten to the part about handling multiple year spans, so I didn't do anything with it. Your input validation could also be improved by using a loop with simpler tests. I left that blank for you to fill in.
-Prelude