If a Statement happens twice, triggers another statment

Im working with a loop and a few if statements within the loop. I'm using rand() % 100+1 to generate a random number, and from that number I'm having different outcomes. If the same outcome happens twice though I want something different to happen. How would I get this to work?

1
2
3
4
5
6
7
8
9
10
11
12
int m = 10
int n = 10
 while()
 {
   int chance;
   m--;
   chance = rand() % 100 + 1;
     if(chance >= 50)
       n++;
     if(chance < 50)
       n--;
 }


So if n-- occurs twice in a row during the loop, I want n++ to occur no matter what chance equals. And after that it goes back to the normal chance.
Last edited on
Use bool:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int m = 10
int n = 10
bool chance_was_below_50 = false;
 while()
 {
   int chance;
   m--;
   chance = rand() % 100 + 1;
     if(chance_was_below_50 || (chance >= 50))
{
       n++;
chance_was_below_50 = false;
}
     if(chance < 50)
{
       n--;
chance_was_below_50 = true;
}
 }
Thanks, that was a lot of help.
Topic archived. No new replies allowed.