counting number of "*" around a apoint in matrix

the problem is to find the number of astriks around a point in c++

im getting this as an answer
9 1 0 0
1 2 1 0
0 9 1 0
0 1 1 0

but this is supposed to be the answer

9 1 0 0
1 2 1 0
1 9 1 0
1 1 1 0


could you tell me where did i go wrong >,<
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string arr[4][4]={{"*",".",".","."},{".",".","*","."},{".",".",".","."},{".",".",".","."}};
	int ar[4][4];
	for(int Col =0 ; Col < 4 ; Col++){
		for(int Row =0; Row < 4 ; Row++){
			ar[Col][Row]=0;
		}
	}
	for(int Row =0 ; Row < 4 ; Row++){ //adding one to what's around the asterik which are 8 squares 
		for(int Col =0; Col < 4 ; Col++){
			if(arr[Col][Row] == "*"){
				ar[Col][Row] = 9;
				if(Col-1 > 0)
				{
					ar[Col-1][Row]++;
				}
				if(Col+1 < 4)
				{
					ar[Col+1][Row]++;
				}
				if(Row+1 < 4)
				{
					ar[Col][Row+1]++;
				}
				if(Row-1 > 0)
				{
					ar[Col][Row-1]++;
				}
				if(Row+1 < 4 && Col+1 < 4)
				{
					ar[Col+1][Row+1]++;
				}
				if(Row+1 < 4 && Col-1 > 0)
				{
					ar[Col-1][Row+1]++;
				}
				if(Row-1 > 0 && Col+1 < 4)
				{
					ar[Col+1][Row-1]++;
				}
				if(Row-1 > 0 && Col-1 > 0)
				{
					ar[Col-1][Row-1]++;
				}
			}

		}
	}
	for(int Col =0 ; Col < 4 ; Col++){
		for(int Row =0; Row < 4 ; Row++){
			if(Row < 3)
			{
			cout<<ar[Row][Col]<<" ";
			}
			else
			{
				cout<<ar[Row][Col]<<endl;
			}
	    }
	}
}
I think you need >= 0 rather than > 0 in lines 18, 30, 38, 42 and 46.
OMG im such an idiot how did i miss that .. thanks a lot saved my day <3
Topic archived. No new replies allowed.