### Trouble understanding Leap year function

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 ?

 ``1234567891011121314151617181920212223242526272829`` ``````#include #include 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
 ``12345`` ``````for (int i=1992; i < 1997; i++) { isALeapYear (i); cout << i << " " << "Return: " << isALeapYear(i) << endl; }``````
`cout << i << " " << isALeapYear(i) << endl;`
Function name in expressions is converted implicitly to the bool type

cout << i << " " << "Return: " << isALeapYear << endl;

So you will always get output

 `Return: 1`

You should write

cout << i << " " << "Return: " << isALeapYear( i ) << endl;
Topic archived. No new replies allowed.