我正在一個date validation
(MM/DD/YYYY)和收到這個錯誤:DD/MM/YYYY輸入驗證
error: lvalue required as left operand of assignment
在線路: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; }
}
}
任何人都可以解釋錯誤(以及我做錯了什麼)嗎?乾杯!!
&&和||也許? – tmpearce 2012-04-17 23:35:57
@tmpearce:在現代版本的C++中,'和'和'or'是有效的關鍵字,不同的拼寫方法'&&'和'||'。 – 2012-04-17 23:36:45
@GregHewgill啊,不錯 - 是那些短路?我應該考慮在某些時候升級編譯器。 – tmpearce 2012-04-17 23:38:06