need help with while

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
while(x=(n+1)/2)
                    {
                    luck_centre = rand() % 100 + 1;
                                  if(luck_centre<=((1-(2*p/3))*100)){x--;y++;}
                                  if(((1-(2*p/3))*100<luck_centre)&&(luck_centre<=(1-(p/3))*100)){y++;}
                                  if((((1-(p/3))*100)<luck_centre)){x++;y++;}
                                  }

    
    
                     while(x!=(n+1)/2)
                     {
                    luck_else = rand() % 100 + 1;
                                  if(luck_else<=  ((5-3*p)/6)*100){x--;y++;} 
                                  if((((5-(3*p))/6)*100<luck_else)&&(luck_else<=((1-(p/3))*100))){y++;}
                                  if((((1-(p/3))*100)<luck_else))
                                        {                                   
                                         if(x<(n+1)/2){x--;y++;}
                                         if(x>(n+1)/2){x++;y++;}
                                         }
             }  


hello my problem is as you can see while x is equals to n+1/2 the first while works; and for example it increases x by 1 . then the second while works because the program works from top to bottom.I dont want them work both. I want my program to return just above the first while after one of these whiles works. How can i do it? thanks for help
Last edited on
= is an assignment. == is equality.
this is not actually the code. And it is not the thing i am asking? can you help me with the while part please? thanks
hello my problem is as you can see while x is equals to n+1/2 the first while works


The condition of the first while is not specified to check for equality. It's checking for assignment. As long as something is being transferred to x, it will return true.

while(x=(n+1)/2)

= is not equality. The first while loop is not working as intended, the second one is.

Edit: Never mind that seems to work as you describe. I don't really understand what you're trying to ask though. What is the actual code any way?
Last edited on
The previous posts pointed out that the wrong operator "=" was used instead of "==". You should heed that advice.

Please see "Relational and equality operators" here:
http://www.cplusplus.com/doc/tutorial/operators/

I AM TELLING YOU THAT THIS IS NOT THE REAL CODES! I AM ASKING SMETHING ABOUT THE WHILE! NOT THE EQUATIONS! DO I HAVE TO OPEN A NEW TOPIC AGAIN ?
Thanks for the reply. You could simply post the real code here, maybe?

Is this what you are trying to do?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
while (true)
{
    if (something)
        
        while (something)
        {
            do some stuff
        }
        
    else                                                                 
        
        while(something_else)
        {
            do some other stuff
        }  
}
Last edited on
I think he's straight up assuming that both while loops will work on every run, but he doesn't want that. He wants the program to run only one while loop, either the first or second one, and after that return the result of the first loop.

I don't get it.
Topic archived. No new replies allowed.