0

私はdate validation(MM/DD/YYYY)に取り組んでおり、このエラーが発生しています:

エラー: 代入の左オペランドとして左辺値が必要です

行:9 ( if ( Y%4=0 ) { return true; }) で、このコードを実行していますか?

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; }
    }   
}

誰でもエラーを説明できますか(そして私が間違っていることは何ですか)教えてください。乾杯!!

4

1 に答える 1

5
    if ( Y%4=0 ) { return true; }        

Should be:

    if ( Y%4==0 ) { return true; }        

An lvalue is an expression that refers to some location in memory. Y%4 is an rvalue -- it cannot be assigned to, semantically speaking.

于 2012-04-17T23:35:37.667 に答える