int length;
int height;
int L;
int H;
char r;
string s;
int c;
int hop;
int q;
int d;
double per;
double w;
double u;
double p;
s = "*";
cout << "What is the transmition range?" << endl;
cin >> hop;
if (hop == 1)
{
H = height;
do
{
L = 0;
do
{
q = H + 1;
if (grid[H][L] == s && grid[q][L] == s)
{
cout << "Point (" << H << "," << L
<< ") and (" << q << "," << L
<< ") can communicate." << endl;
}
q = H - 1;
if (grid[H][L] == s && grid[q][L] == s)
{
cout << "Point (" << H << "," << L
<< ") and (" << q << "," << L
<< ") can communicate." << endl;
}
q = L + 1;
if (grid[H][L] == s && grid[H][q] == s)
{
cout << "Point (" << H << "," << L
<< ") and (" << H << "," << q
<< ") can communicate." << endl;
}
q = L - 1;
if (grid[H][L] == s && grid[H][q] == s)
{
cout << "Point (" << H << "," << L
<< ") and (" << H << "," << q
<< ") can communicate." << endl;
}
L = L + 1;
}
while (L <= length);
H = H - 1;
cout << endl;
}
while(H > -1);
}
return 0;
}
I think you're stepping out of bounds of your array:
1 2 3
(line 23) H = height;
(line 31) q = H + 1;
(line 32) if (grid[H][L] == s && grid[q][L] == s)
in order for this code to work, 'grid' would need to be 2 rows taller than 'height', which doesn't make sense.
I didn't look too closely but you're probably making off-by-one mistakes like this all over the place. Remember that if an array is 5 elements large, you can only index with 0-4. You cannot index by 5. IE:
1 2 3 4
int foo[5];
foo[4] = 0; // this is okay
foo[5] = 0; // this is BAD