can anyone explain why this isnt working? The printf that ive hidden from the compiler seems to cock it up??
CODE:
#include <stdio.h>
#include <clib.h>
struct dat{
int day;
int month;
int year;
};
main()
{
char loop ='y';
while (loop == 'y'||loop == 'Y')
{
int leap, *mt, *yr, *ly, i,day, day1, year1, month1, leap_yr, year2, month2, total;
struct dat t;
static char 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}
};
system ("cls");
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 );
if (t.day <= 0)
printf("ERROR, there are no months with that number of days!\n");
else if (t.month > 12 ||
t.month <= 0)
printf("ERROR, there are no years with that many months!\n");
else if ((t.month == 1||
t.month == 3||
t.month == 5||
t.month == 7||
t.month == 8||
t.month == 10||
t.month == 12) && t.day > 31)
printf("ERROR, the month you have entered doesnt have that many days in it!\n");
else if ((t.month == 4||
t.month == 6||
t.month == 9||
t.month == 11) && t.day > 30)
printf("ERROR, the month you have entered doesnt have that many days in it!\n");
else if (t.month == 2 && t.day == 29 && leap == 0)
printf("ERROR, the year you've entered isn't a leap year!\n");
else if (t.month == 2 && t.day > 29 && leap != 0)
printf("ERROR, although this is a leap year, there arnt that many days in February!\n");
{
if (t.month == 1)
month2 = 31;
else if( t.month == 2)
month2 = 28;
else if( t.month == 3)
month2 = 31;
else if( t.month == 4)
month2 = 30;
else if( t.month == 5)
month2 = 31;
else if( t.month == 6)
month2 = 30;
else if( t.month == 7)
month2 = 31;
else if( t.month == 8)
month2 = 31;
else if( t.month == 9)
month2 = 30;
else if( t.month == 10)
month2 = 31;
else if( t.month == 11)
month2 = 30;
else if( t.month == 12)
month2 = 31;
}
{
year2=(2002-t.year)*365;
if(leap == 0)
leap_yr=1;
else
leap_yr=0;
total = t.day+month2+year2+leap_yr;
// printf("There are %d days until the 25/12/2002\n\n" total);
}
printf("Would you like to enter another date? (Y/N)\n");
scanf("\n%c",&loop);
}
}