loops in functions...why does one example work but the other doesnt?

so i have this board called brdray it has bunnies on it and when one is above the other the program will dynamicaly create a new object, each go they will move randomly.

i have a function called clear board, its uses nested for loops to sweep through brdray and whenever it encounters an f or m it resets the board to x which is a blancspace

its here...it works fine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void clearboard (char brdray[10] [10])
{
    char x=' ';

    char f='f',F='F',m='m',M='M';
for (int a = 0;a<10;a++)
 {
     for (int b =0;b<10;b++)
       {
           if ((brdray [a] [b]==f)||(brdray [a][b]==m)||(brdray [a][b] == F)||(brdray[a][b]==M))
            {
                brdray [a] [b]=x;

            }
}
}
}



this is supposed to sweep through in the same way, just that one int that represents the index number is set to - 1, this way if an m is above an f
so..
brdray [1][1]==m and brdray [2][1] ==f will be the argument for the if statement to roll on... so why baint it work?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void makebabies (char brdray[10] [10])
{
    char x=' ';
    char f='f',F='F',m='m',M='M';

for (int a = 0;a<10;a++)
 {
     for (int b =0;b<10;b++)
       {
           char z= '*';
           int apos;
           int aneg;
           int bpos;
           int bneg;
           apos=a;
           apos+1;
           if ((brdray [a][b] == f) && (brdray[apos][b]==m))//if f is above m
            {
               brdray //does its stuff


            }
}
}
}


or bellow f or whatver i keep running the board in lota of different combinations


and why does this fill the whole board with *


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void makebabies (char brdray[10] [10])
{
    char x=' ';
    char f='f',F='F',m='m',M='M';

for (int a = 0;a<10;a++)
 {
     for (int b =0;b<10;b++)
       {
           char z= '*';
           int apos;
           int aneg;
           int bpos;
           int bneg;
           apos=a;
           apos+1;
           if ((brdray [a][b] == f)==(brdray[a][b]==f) )//if f is above m
            {
               brdray [a] [b] = z;


            }
}
}
}
Last edited on
I am sorry I have not understood what you want to do. But I see unclear code

1
2
           apos=a;
           apos+1;


What does mean expression apos+1; ?
Last edited on
apos+1;
Did you mean apos=apos+1; ?
oooooh yeah!
well that was dumb, i tried EVERYTHING and my basic stuff was weak...still i cant suss out why some things had occured but now i can experiment...cheers guys that musve been to easy for you, i will come across a hard one soon enuff
and why does this fill the whole board with *

Because this if ((brdray [a][b] == f)==(brdray[a][b]==f) ) is always true.
Topic archived. No new replies allowed.