Maybe this should belong in the logic section. But since this is C++, ill put it here.(adsbygoogle = window.adsbygoogle || []).push({});

bool isLeapYear( int y)

{

return y%4==0 && y % 100 !=0 || y% 400==0 ;

}

They said it returns when y is divisible by 4 but not by 100 unless it is also divisible by 400.

This is a bit confusing since I thought that statements are binary. that is its either A and(BorC) or (AorB)andC. I mean we get statements like (A and B and B) b/c [A and (B and C)]=[A and B and C]. Same thing for the or operator. But I can't see how (A and B or C) results from a binary logical statement involving two sets.

Do they mean (y%4==0 && y % 100 !=0 || y% 400==0) is the same as

(y%4==0) && (y % 100 !=0 || y% 400==0)?

It would make a lot more sense b/c

(y%4==0) && (y % 100 !=0 || y% 400==0) is the same as

(y%4==0 && y % 100 !=0) ||(y%4==0 && y% 400==0)

which is the same as the statement:y is divisible by 4 but not by 100 unless it is also divisible by 400.

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Confused about logical statements in C++

Loading...

Similar Threads - Confused logical statements | Date |
---|---|

Where is the faulty logic in my solution to this problem? | Jun 20, 2017 |

Python Recursion in python functions -- confusion | Feb 5, 2017 |

Python Nested For-loop confusing, how does program proceed? | Oct 12, 2016 |

Python Beginner coding exercise confusion | Oct 1, 2016 |

I'm confused about why this object is null | Nov 14, 2015 |

**Physics Forums - The Fusion of Science and Community**