Leap year program prints wrong output
Hi,
This program is supposed to print all the leap year between any two given years. It seems to work when the gap between years is huge, but when I enter 1991 and 2005 for example, it will only tell me that 2000 is a leap year, when years such as 92,96, and 04 are also leap years, right?
Any ideas where Iv'e gone wrong?
Code:
#include <stdio.h>
#include <process.h>
#include <values.h>
int main(void)
{
char your_name[12];
int year_start;
int year_finish;
int leap_yr_input = 0;
int leap_yr_test = 0;
int maxint_value;
int i;
int yr_test;
int nearest_leap_yr;
system("cls");
printf("\nPlease enter your name(e.g. Jan): ");
scanf("%s", your_name);
maxint_value = MAXINT;
do
{
printf("\nEnter year to begin with between 1 and %d: ", maxint_value - 1);
scanf("%d", &year_start);
printf("\nEnter an ending year between %d and %d(e.g. %d): ",
year_start + 1, maxint_value, year_start + 1);
scanf("%d", &year_finish);
printf("\n");
if(year_start >= year_finish)
{
printf("\nInvalid input!");
printf("\nThe ending year must be bigger than the starting year!");
printf("\n\nRe-enter years");
}
}
while( year_start >= year_finish );
printf("\nHello %s!", your_name);
printf("\n");
printf("\nYour starting year is: %d", year_start);
printf("\nYour ending year is: %d", year_finish);
printf("\n\n");
for( i = year_start; i <= year_finish; i++ )
{
if( i % 4000 != 0 )
{
if( i % 4 == 0 )
{
if( i % 400 == 0 )
{
leap_yr_input = 1;
printf("\nThe year %d is a leap year", i);
}
}
}
}
if( leap_yr_input == 1 )
printf("\n\nThis is the end of LEAP year list");
if( leap_yr_input == 0 )
{
printf("\nThere are no leap years in your input range");
for( yr_test = year_finish + 1; yr_test <= maxint_value; yr_test ++)
{
if(yr_test % 4000!= 0)
{
if(yr_test % 4 == 0)
{
if(yr_test % 400 == 0)
{
leap_yr_test = 1;
nearest_leap_yr = yr_test;
break;
}
else if(yr_test % 100 != 0)
{
leap_yr_test = 1;
nearest_leap_yr = yr_test;
break;
}
}
}
}
if( leap_yr_test == 0)
{
printf("\nThere is NO leap year in the range between ");
printf("your input and MAXINT");
}
if(leap_yr_test == 1)
{
printf("\n\nThe nearest leap year that is greater than your input ");
printf("is: %d", nearest_leap_yr);
}
}
printf("\n");
printf("\nThanks for using this program! ");
printf("Good-bye!");
system("pause");
}