function inside IF statement ignored

Hi all,

yesterday I spent the whole day on a problem I simply won't be able to figure out. I got an IF statement inside a while loop and the IF statement contains a function call. The function only changes coordinate values but to make sure that I didn't type something wrong in it I changed it to a simple cout statement. But the function is completely ignored for some reason. Here's what I got:

function:

void addblocksize2()
{pixelx=pixeloldx;pixely=pixeloldy;

if ((pixelx+blocksize)<iw){pixelx=pixelx+blocksize;}
else {pixelx=(blocksize/2);pixely=pixely+blocksize;}}

...
...
while loop

...

if (qq==qqmax){npixelcor[runner2]=-10000;npixelcor[runner2+1]=-10000;runner2=runner2+2;addblocksize2;cout<<"pixelx";cout<<pixelx;cout<<"\n";break;}


I also added the two couts before the function call:

...cout<<"pixelx";cout<<pixelx; addblocksize2;cout<<"pixelx";cout<<pixelx; ...

to see if there was any change in the value but it stays the same.

(again, I altered the funtion above to ... {cout << "here";} but nothing happens (no ''here'' appears in the dosbox). What am I doing wrong or should it be impossible to call a function in that if statement?

Cheers
Stephan
closed account (zb0S216C)
Can you post the code in the proper format? I can't predict what happens in your while loop if you miss-out sections of the code.

Wazzak
Last edited on
HI Wazzak,

yep, it's quite long though and actually it's two while loops nested inside a for loop but I thought that this may be irrelevant as everything else works just fine. Ok, here it is:

while (true){if (qq==qqmax){break;}

if (check==1){break;}
if (gfound==1){break;}

pixeloldx=pixelx;pixeloldy=pixely;

if (check==0){calculation();comparison();}

if (check==1){break;}
if (gfound==1){break;}

pixelx=pixelx+1;

if (check==0){calculation();comparison();if (gfound==1){break;}}
if (check==1){break;}
pixely=pixely+1;

while (true){
qq=qq+2;cout <<qq;cout <<" ";cout<<gfound;cout<<"\n";
if (qq==qqmax){npixelcor[runner2]=-10000;npixelcor[runner2+1]=-10000;runner2=runner2+2;addblocksize2;cout<<"pixelx";cout<<pixelx;cout<<"\n";break;}
for (kkk=0;kkk<qq;kkk++)
{pixelx=pixelx-1;
calculation();comparison();if (gfound==1){break;}}

... then comes a lot of other for loops (like the one above this line) and then the while loops are closed. Maybe it's the qq==qqmax condition in the 1st while loop?
closed account (zb0S216C)
If the code is too big, try posting the code on Pastebin[1]. From there, I will be able to read you code fully. Also, make sure that you select the correct language. When you've posted the code, post the link here.

References:
[1]http://pastebin.com/

Wazzak
Last edited on
please find the code in my last post :-)

edit: I have circumvented the function by simply writing it's content into the IF condition. Now it works and for me that suffices. I guess it's because of the first while loop which also contains the condition qq==qqmax. Probably it won't 'jump' to the function anymore if the condition is met. Anyway, thanks for your help!

Cheers
Stephan
Last edited on
closed account (zb0S216C)
addblocksize2( ) is a function. In your first while loop, you call addblocksize2( ) without the parentheses( you need these ).

Wazzak
how in the world could I overlook that ?! Thx Wazzak
Topic archived. No new replies allowed.