I have some problem with my code about mode

This code supposed outputting the mode of the input, problem is, this code just outputting 0. Do you guys have any idea?

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
  #include <iostream>
using namespace std;

int main ()
{
	int n;
	cin >> n;
	int arr[1001] = {0}, check = 0;
	
	for (int i=0; i < n; i++)
	{
		int a;
		cin >> a;
		if (a > check)
		{
			check = a;
		}
	}
	
	int m = 0, mode = 0;
	for (int i = 1; i <= check; i++)
	{
		if (arr[i] > 0)
		{
			if (arr[i] > m)
			{
				m = arr[i];
				mode = i;
			}
			else if (arr[i] == m & i > mode)
			{
				m = arr[i];
				mode = i;
			}
		}
	}
	
	cout << mode << endl;
	
	return 0;
}
oh i already figure it out, sorry for asking!
if anyone want the answer, it's in line 13. I forgot to add a line.

 
arr[a]++;
Topic archived. No new replies allowed.