Help with a perfect number detector using pointers

Howdy folks, like the title says I have a homework assignment to code a perfect number detector in range 0 to a number input by the user.

just in case: <http://en.wikipedia.org/wiki/Perfect_number>

It runs, but sometimes freezes while checking numbers nearby 50, 250, and 450. Even stranger, I input 100, got a glitch; I tried again, and it ran right through. Do I have pointer issues? Math issues? Visual Studio issues?

Code below (I've left line 23 uncommented so you can see where it freezes while running.)

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

bool is_perfect(int &num);

int main()
{
	int *num;
	int *perfects;
	int *p_count;
	num = new int;
	p_count = new int;
	perfects = new int;
	*p_count = 0;

	int *i;
	i = new int;

	cout << "Please enter the number to check:  ";
	cin >> *num;
	for ((*i)=1; (*i)<=(*num); (*i)++)
	{
		cout << "inside main loop @ " << *i << endl;
		if (is_perfect(*i)==true)
		{
			cout << "	perfect found!" << endl; 
			*(perfects + (*p_count)) = (*i);
			(*p_count)++;
		}
	}

	cout << "**************************" << endl;
	cout << "Perfect numbers <" << *num << endl;

	for ((*i)=0;(*i)<(*p_count); (*i)++)
	{
		cout << *(perfects + (*i)) << "  ";
	}
	cout << endl << "**************************";

	cin.get();
	cin.get();
}

bool is_perfect(int &num)
{
	int *n;
	n = &num;

	int *divs;
	int *L_divs;
	divs = new int;
	L_divs = new int;
	*L_divs = 0;

	int *i;
	i = new int;
	
	//cout << "is_perfect() evaluating " << *n << "..." << endl;

	for ((*i)=1; (*i)<(*n); (*i)++)
	{
		if (((*n)%(*i))==0)
		{
			//cout << "	adding divisor " << *i << endl;
			*(divs+*L_divs) = *i;
			(*L_divs)++;
		}
	}

	int *sum;
	sum = new int;
	*sum = 0;

	//cout << "		before adding *sum=" << *sum << endl;

	for ((*i)=0; (*i)<(*L_divs); (*i)++)
	{
		(*sum) += *(divs+*i);
		//cout << "		sum is now " << *sum;
	}

	//cout << endl << "	sum of divisors: " << *sum << endl;

	if ((*sum) == (*n))
	{
		//cout << "		returns true" << endl;
		return true;
	}
	else
	{
		//cout << "		returns false";
		return false;
	}

	delete n;
	delete divs;
	delete L_divs;
	delete sum;
	delete i;
}


Thanks in advance for any help, I hope to be answering questions instead of asking them soon! : )
¿why the fuck are you using dynamic allocation?

*(perfects + (*p_count)) = (*i); is accessing out of bounds.
Well I'd recommend not using pointers like that for starters.
Believe me, I'd love to not be using dynamic allocation like this, but it's part of the assignment.

*(perfects + (*p_count)) = (*i);
This line must be working or else it wouldn't ever return proper output...

Is there some property of declaring new space for something that I'm clearly oblivious of? I'm kind of stumped, it only freezes one in five times with input: 100, but always when input: 1000.
1
2
*(perfects + (*p_count)) = (*i);
This line must be working or else it wouldn't ever return proper output... 

Well, following:
1
2
3
int x[5];
x[8] = 10;
cout << x[8];

works too, but still can lead to unexpected behavior.
Right so its some dynamic glitch we didn't cover in lecture cuz its a beginner class. Cool!

Thanks for helping guys!
No, it's you writing out of bounds, which causes undefined behaviour.
perfects = new int; ¿how much space are you reserving?
Topic archived. No new replies allowed.