>>any ideas how to fix it?
fix what? you didn't say what's wrong with the code you posted.
why does isLeapYear() take a double as parameter? It should be an integer; afterall years do not contain fractions.
Ancient Dragon
Retired & Loving It
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
read the assignment again, and re-read it again and again until you understand it. IsLeapYear() is supposed to return TRUE if the year is a leap year or FALSE is the year is not a leap year. The function LeapYear() that you posted seems to do that. The functon IsLeapYear() that you posted does not do that, actually I have no clue what its purposes is. Delete IsLeapYear() and rename LeapYear() function to IsLeapYear().
In function main() you have to enter two years -- your program only gets one year. Then also in main() you need to create a loop that calls IsLeapYear() for each year between the first and second years that you enter from the keyboard.
Don't forget -- years prior to 1582 AD do not have leap years because the Gregorian calendar wasn't created until February 24, 1582.
Ancient Dragon
Retired & Loving It
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
The function doesn't have to return a value to be able to display what the year is.
void leapYear(int year)
{
if((year % 100) == 0 )
{
printf("%d is a century year\n", year);
}
else if(((year % 4) == 0) || ((year % 400) == 0))
{
printf("%d is a leap year\n", year);
}
else
{
printf("%d is a not century\n", year);
}
}
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
>The function doesn't have to return a value to be able to display what the year is.
It does according to the assignment:
You must write a separate function called isLeapYear that takes a year as a parameter and returns whether or not that year is a leap year.
Plus, as I see it, the program was supposed to be in C++, not C.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
int leapYear(int year)
{
return((!(year % 100 == 0))&&((year % 4 == 0) || (year % 400) == 0));
}
This will return if is a leap year or not.
call it inside a loop that will start with the first year and stop at the wanted one.
Inside the loop
if( leapYear( year ))
{
printf("%d ", year);
}
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
You must write a separate function called isLeapYear that takes a year as a parameter and returns whether or not that year is a leap year. - not sure how
also not sure how to get it to print up to five leap years per line.
Looks like you have almost completed the assignment. To print 5 leap years per line I would add another counter in that loop to count the number of leap years printed on the line -- when the counter reaches 5 then print a "\n";
int counter = 0;
for(int i = x; i <= z; i++)
{
if (isLeapYear(i))
{
cout << i << " ";
if( ++counter == 5)
{
cout << "\n";
counter = 0;
}
}
}
Ancient Dragon
Retired & Loving It
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342