RUN TIME ERROR

In my first homework about class, I have to create a program similar to a social network that finds the max amount of friends among those existing IDs.
A pair of friends establish only when each other sends request to the counterpart.
the problem is that although some of the testing files get passed, almost of them returns RTE, I'm not sure but those arrays seems reasonable for me.
May anyone help me to find the problematic spots?

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
  #include <iostream>
using namespace std; 
class Person
{
	int id;
	unsigned int friendCount;
	int* friendList;
	int prcnt;
public:
	Person(int id);
	~Person();
	int getId() const;
	bool addFriend(int anId);
	bool unfriend(int anId);
	inline static void paircount(Person* [],const int&);
};
Person::Person(int id)
{
	this->id=id;
	friendCount=0;
	friendList = new int [1000];
	prcnt=0;
} 
int Person::getId() const
{
	return id;
}
bool Person::addFriend(int anId)
{
	if(anId!=this->id)
	{
		for(int i=0;i<this->friendCount;i++)
			if(anId==friendList[i])
				return false;
		this->friendList[friendCount] = anId;
		this->friendCount++;
		return true;
	}
	else 
		return false;
}
bool Person::unfriend(int anId)
{
	for(int i=0;i<friendCount;i++)
	{
		if(anId==friendList[i])
		{
			friendCount--;
			for(int j=i;j<friendCount;j++)
				friendList[j]=friendList[j+1];
			return true;
		}
	}
	return false;
}
Person::~Person()
{
	delete [] friendList;
}
inline void Person::paircount(Person* ID[], const int& i) 
{
	int count=0;
	int max=-1; 
	for(int j=0;j<i;j++)
	{
		for(int k=0;k<ID[j]->friendCount;k++)
			for(int l=0;l<i;l++)
			{
				int temp = ID[j]->prcnt;
				if(l==j)
					continue;
				for(int m=0;m<ID[l]->friendCount;m++)
					if(ID[j]->getId()==ID[l]->friendList[m] && ID[j]->friendList[k]==ID[l]->getId())
					{
						ID[j]->prcnt++;
						break;
					}
				if(temp!=ID[j]->prcnt)
					break;
			}
		if(max<ID[j]->prcnt)
			max=ID[j]->prcnt;
	}
	for(int j=0;j<i;j++)
		if(ID[j]->prcnt==max)
			cout<<ID[j]->getId()<<" ";
	cout<<max;
}
int main()
{
	int i=0;
	char event = 0;
	Person** ID = new Person* [1000];
	while(cin>>event)
	{
		if(event=='N')
		{
			int id;
			cin>>id;
			ID[i] = new Person(id);
			i++;
		}
	
		if(event == 'A')
		{
			int reqst = 0, recei = 0;
			cin>>reqst;
			cin>>recei;
			for(int j=0;j<i;j++)
				if(ID[j]->getId()==reqst)
				{
					ID[j]->addFriend(recei);
					break;
				} 
		}
		if(event == 'R')
		{
			int rem = 0, coutprt = 0;
			cin>>rem>>coutprt;
			for(int j=0;j<i;j++)
				if(ID[j]->getId()==rem)
				{
					ID[j]->unfriend(coutprt);
					break;
				}
		}
	}
	Person::paircount(ID,i);
	delete [] ID;
	ID = NULL;
}



thnks for mutexe's reply, but my compiler tells nothing to me concerning the reason of runtime error.
thanks for Computergeek01's reply, the input file should be right since it's written by my teacher, and that's the only way I can assume.
Last edited on
your compiler/ide should tell you which line you're getting your runtime error.
+1 mutexe addendum: when run in debug mode.

What type of run-time error are you getting? They are not all the same, and it would help narrow the issue down if it came with an error code and\or possibly a faulting module as well. If you want to program then you should lose the idea that errors are meaningless gibberish, they often tell you exactly what is wrong. I ran your code and didn't see any immediate issues, could the problem be with the input file you mention?
Topic archived. No new replies allowed.