I am working on a date validation (MM/DD/YYYY) and getting this error:
error: lvalue required as left operand of assignment
at line:9 (if ( Y%4=0 ) { return true; }) running this piece of code?
bool valDate( int M, int D, int Y )
{
if (! (1<=M and M<=12) ) return false;
if (! (1<=D and D<=31) ) return false;
if ( (D==31) and (M==2 or M==4 or M==6 or M==9 or M==11) )
return false;
if ( (D==30) and (M==2) ) return false;
if ( (M==2) and (D==29) ) {
if ( Y%4=0 ) { return true; }
else { return false; }
if ( (Y%100==0) and (Y%400==0) ) { return true; }
else { return false; }
}
}
Can anyone explain the error (and what’s I’m doing wrong) please? Cheers!!
Should be:
An lvalue is an expression that refers to some location in memory. Y%4 is an rvalue — it cannot be assigned to, semantically speaking.