943,692 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 8252
  • C++ RSS
Nov 12th, 2008
0

function to check leap year

Expand Post »
C++ Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 6
Solved Threads: 0
Light Poster
AcidG3rm5 is offline Offline
25 posts
since Oct 2008
Nov 12th, 2008
0

Re: function to check leap year

Change = to ==
Reputation Points: 350
Solved Threads: 63
Posting Pro
invisal is offline Offline
562 posts
since Mar 2005
Nov 12th, 2008
1

Re: function to check leap year

Keep it simpler, it's C++, not Pascal :
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Nov 12th, 2008
0

Re: function to check leap year

thanks for the tips. Still new to c++. Will be trying to improve my codes. :>
Reputation Points: 6
Solved Threads: 0
Light Poster
AcidG3rm5 is offline Offline
25 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Need insight in assignment
Next Thread in C++ Forum Timeline: Link Loki to app in Visual C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC