function to check leap year

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 16
Reputation: AcidG3rm5 has a little shameless behaviour in the past 
Solved Threads: 0
AcidG3rm5 AcidG3rm5 is offline Offline
Newbie Poster

function to check leap year

 
0
  #1
Nov 12th, 2008
  1. //checks for leap year
  2. bool checkLeapYr(int year)
  3. {
  4. bool isLeap;
  5. if ((year%4=0) && (year %100!=0) || (year%400=0)) //error here. Non-Ivalue assignment
  6. {
  7. isLeap=true;
  8. return isLeap;
  9. }
  10. else
  11. {
  12. isLeap=false;
  13. return isLeap;
  14. }
  15. }//end function check leap year

i have the above function to check if a year is a leap year. The if statement is giving me a compilation error message "non-lvalue in assignment". Can anyone help me with it please?

Thank you.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: function to check leap year

 
0
  #2
Nov 12th, 2008
Change = to ==
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: function to check leap year

 
0
  #3
Nov 12th, 2008
Keep it simpler, it's C++, not Pascal :
  1. //checks for leap year
  2. bool checkLeapYr(int year)
  3. {
  4. return year%4 == 0 && (year %100 != 0 || year%400 == 0);
  5. }//end function check leap year//checks for leap year
Last edited by ArkM; Nov 12th, 2008 at 9:42 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 16
Reputation: AcidG3rm5 has a little shameless behaviour in the past 
Solved Threads: 0
AcidG3rm5 AcidG3rm5 is offline Offline
Newbie Poster

Re: function to check leap year

 
0
  #4
Nov 12th, 2008
thanks for the tips. Still new to c++. Will be trying to improve my codes. :>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC