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

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2007
Posts: 4
Reputation: seanw is an unknown quantity at this point 
Solved Threads: 0
seanw seanw is offline Offline
Newbie Poster

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

 
0
  #1
Aug 5th, 2007
Hi, I am having a strange problem with a simple process. Heres the code.
  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

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

 
0
  #2
Aug 5th, 2007
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.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 4
Reputation: seanw is an unknown quantity at this point 
Solved Threads: 0
seanw seanw is offline Offline
Newbie Poster

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

 
0
  #3
Aug 5th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

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

 
0
  #4
Aug 5th, 2007
What you really have is this
     if(inCrem == tgPlacers.size())
     {
        /* The ; at the end of your if is a NO-OP */
     }
     {
           Anything = false;
           break;
     }
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 4
Reputation: seanw is an unknown quantity at this point 
Solved Threads: 0
seanw seanw is offline Offline
Newbie Poster

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

 
0
  #5
Aug 5th, 2007
AH!! Very surprised I didn't see that.

thanks guys
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1975 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC