Mar 27, 2013 at 7:50pm UTC
When I run this, the return value is always "1".
I left in my test code
I'm trying to figure out why the return value is always 1 and how to fix it.
Just to make sure I'm correct, I think the return should be "0" if it's leap year correct ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include <iostream>
#include <cmath>
using namespace std;
bool isALeapYear( int year )
{
// Test code
cout << year << " " ;
cout << year %4 << " " ;
cout << year %100 << " " ;
cout << year %400 << " " << endl;
// Test code
if (year %4==0)
{cout << year << " " << "leap year" << endl;}
/* Check if the year is divisible by 4 or is divisible by 400 */
return ((year % 4 == 0 && year % 100 != 0) || ( year % 400 == 0));
}
int main()
{
for (int i=1992; i < 1997; i++)
{
isALeapYear (i);
cout << i << " " << "Return: " << isALeapYear << endl;
}
return 0;
}
PS. this is for personal learning, not school work, although I got the idea from some school projects I have seen on here.
Last edited on Mar 27, 2013 at 7:53pm UTC
Mar 27, 2013 at 8:02pm UTC
cout << i << " " << isALeapYear(i) << endl;