944,095 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 2345
  • C++ RSS
Aug 5th, 2007
0

1 does not equal 5, but my code thinks so...

Expand Post »
Hi, I am having a strange problem with a simple process. Heres the code.
C++ Syntax (Toggle Plain Text)
  1.  
  2. bool areNumbers = true;
  3. bool Anything = true;
  4. int numBytes = 1;
  5. long inCrem = 0;
  6. while(gPlacerID != tgPlacers[inCrem]->GetPlacerTypeID())
  7. {
  8. inCrem++;
  9. if(inCrem == tgPlacers.size());
  10. {
  11. Anything = false;
  12. break;
  13. }
  14. }
This code is part of a larger algorithm but I just cut out the part of focus. Say the while loop has been entered and increm gets incremented from 0 to 1. Say tgPlacers.size() is 5.

Now in the if statement when it says if(inCrem == tgPlacers.size()); (for example, if 1 == 5), it goes through to declaring Anything = false, ect. 1 does not equal 5 and it should not be entering the if.

Anyone know why this could be happening? Let me know if you need more info.

Thanks
Last edited by seanw; Aug 5th, 2007 at 4:51 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
seanw is offline Offline
4 posts
since Aug 2007
Aug 5th, 2007
0

Re: 1 does not equal 5, but my code thinks so...

stick a few couts there,

Put inCrem++ after the if clause, and see what happens.
Last edited by iamthwee; Aug 5th, 2007 at 4:58 pm.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Aug 5th, 2007
0

Re: 1 does not equal 5, but my code thinks so...

I tried your suggestions but its still going in..

I debugged through it too and put the variables in the watch and saw that when 1 == 5, it totally enters the if.
Last edited by seanw; Aug 5th, 2007 at 5:12 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
seanw is offline Offline
4 posts
since Aug 2007
Aug 5th, 2007
0

Re: 1 does not equal 5, but my code thinks so...

What you really have is this
     if(inCrem == tgPlacers.size())
     {
        /* The ; at the end of your if is a NO-OP */
     }
     {
           Anything = false;
           break;
     }
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Aug 5th, 2007
0

Re: 1 does not equal 5, but my code thinks so...

AH!! Very surprised I didn't see that.

thanks guys
Reputation Points: 10
Solved Threads: 0
Newbie Poster
seanw is offline Offline
4 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: Help with C++
Next Thread in C++ Forum Timeline: need compiler translation!





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


Follow us on Twitter


© 2011 DaniWeb® LLC