# Thread: Function working wrong :/

1. ## Function working wrong :/

I have a problem here! I have this function: LINK But my function aint working! but first of I have in the construcktor to the class that the function is part of I have done this LINK so I get to the problem straight away...

Anyway I end up getting bricksnumber[] getting bigger than 3! And I dont add values to that except for the one I do if bricksnumber is LESS than 3 ! So how is that possible? Iam still pretty new so I might have missed something!

2. Pastebin is annoying like this.

Code:
```	if(bricks[x1]-1 == 0) //The table is built up with nine slots and the player enters from 1-9, and to make it work with my array I minus one from it so it starts from 0
{
if (bricksnumber[player] < 3) //checks that the player has less than 3 bricks
bricks[x1-1] = briktype;
bricksnumber[player]++;
checkwinner();
}```
Could have unintended evaluation because of your tabbing.

Code:
```	if(bricks[x1]-1 == 0)
{
if (bricksnumber[player] < 3)
{
bricks[x1-1] = briktype;
}
bricksnumber[player]++;
checkwinner();
}```

3. Hard to tell unless you post the actual game class where all those variables are declared.

4. All files here! But they are danish..

http://cpp.sourceforge.net/?show=13809 main.cpp
http://cpp.sourceforge.net/?show=13810 game.cpp
http://cpp.sourceforge.net/?show=13811 game.h (here is the class...)

5. > for (int x=0;x>8;x++)
Never going to happen in winnercheck

6. Originally Posted by Salem
> for (int x=0;x>8;x++)
Never going to happen in winnercheck
Ehh I dont understand what you mean

Anyway to make it short

As you can see the only way bricksnumber can increase is in the "less than 3" check I have, so in my head it should not be able to rise to 4, but it DO sometimes so Iam totaly lost *crying like a child...*

7. Well x starts off at 0
Then you test whether x is greater than 8 (which it isn't)
Then the loop exits because the condition has failed.

8. Found one error! now it aint increasing but still bugged...

Code:
```        if (bricksnumber[player] < 3)
{//checks that the player has less than 3 bricks
bricks[x1-1] = briktype;
bricksnumber[player]++;
checkwinner();
}

that one need the { and }```

9. Originally Posted by Salem
Well x starts off at 0
Then you test whether x is greater than 8 (which it isn't)
Then the loop exits because the condition has failed.
uhh thx stupid syntax error

10. technically not a syntax error :-)

11. anyway I think my code works now

Popular pages Recent additions