### i have two 2day array programs with systems to detect chars on the board, what is wrong with them?

they dont detect anything or they do detect everything...in one case in the bunny game i do have success in clearing the board of all 'm' and 'f' chars...however i have failed to successfully adapt it, ive ties enough to realize there is a simple flaw in my logic but i cant find it-potentially this is easy to solve but i have been over looking 'something' for a long time

first is the bunny code...i hope it still makes sense because it is only the function that scans through the array, all there was was a bunch of ms and fs moving randomly around a board

 ``123456789101112131415161718192021222324252627282930313233`` ``````int 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++) { int babies=0; int apos; int bneg; apos=a; bneg=b; apos=apos+1; if (brdray [a][b] == f&& brdray [apos][b]) { babies=babies+1; cout <<"babies!!!"<

secondly i will give my whole code, you can presume the rest of the code for the one above is simlar,

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145`` ``````#include #include #include #include #include using namespace std; int posx=10; int posy=10; char z='*'; char x=' '; char b='^'; char u='!'; char brdray [20] [20] = { {z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z}, {z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z} }; void move (); void getboard (); char proximity (char brdray [20][20]); int main(){ brdray [10] [10] = b; brdray [5] [5] = u; while (1) { system ("cls"); getboard(); move(); proximity(brdray); system ("pause"); } } void getboard () { for (int a=0;a<20;a++) { for (int b=0;b<20;b++) cout<> enter; switch (enter) { case 1: if(brdray [a][posy]!='*') posx=posx+1; break; case 2: if (brdray [posx][o]!='*') posy=posy-1; break; case 3: if (brdray[posx][e]!='*') posy=posy+1; break; case 4: if (brdray [i][posy]!='*') posx=posx-1; break; } brdray [posx] [posy] = b; } char proximity (char brdray[20][20]) { int n,m,k,l; int j =0; int s =0; for (s;s<20;s++) { for (j;j<20;j++) n=s; m=j; n=n+1; m=m+1; k=s; l=j; l=l-1; k=k-1; if (brdray [s] [j]=='^') { if (brdray [n][j]=='!') { cout << "something"; } if (brdray [k][j]=='"') { cout<< "something else"; } } } }``````
Last edited on
camaaahnnnn
If you'd use proper indentation and names for you variables it'd be much easier for you to understand your own code.

What is this

`if (brdray [a][b] == f&& brdray [apos][b])`

supposed to do?

Do you know the difference between `=` and `==`:
`else if ((brdray [a][b]= f)&& (brdray[apos][b]=m)) //here is another `
?
oh i messed with it so much that i left it it is supposed to be
 `` `` ``if (brdray [a][b] == f&& brdray [apos][b]==m``

i rebuilt it to post...i didnt do a verygood job of tidying...should have ran it got the error message and then pasted it...basicly im trying to show my thinking...but theres problems with copying and pasting
 ``12345678910111213141516`` ``````bool IsMale(char ch) { return (ch == 'm') || (ch == 'M'); } bool IsFemale(char ch) { return (ch == 'f') || (ch == 'F'); } bool IsBunny(char ch) { return IsMale(ch) || IsFemale(ch); } bool IsOppositeGender(char ch1, char ch2) { return (IsMale(ch1) && IsFemale(ch2)) || (IsMale(ch2) && IsFemale(ch1)); }``````
 ``12345678910111213141516171819202122`` ``````int makebabies (char brdray[10] [10]) { int babies=0; for (int a = 0;a<10 - 1;a++) // - 1 is imporant { for (int b =0;b<10 - 1;b++) { if (IsBunny(brdray [a][b])) { if(IsOppositeGender(brdray [a][b], brdray [a+1][b])) // because of +1 we need -1 in the loop above! babies=babies+1; if(IsOppositeGender(brdray [a][b], brdray [a+1][b+1])) babies=babies+1; if(IsOppositeGender(brdray [a][b], brdray [a][b+1])) babies=babies+1; cout <<"babies!!!"<