# Thread: Find Perfect Number generator stops at 6

1. ## Find Perfect Number generator stops at 6

This is a perfect number generator, when you start from 0 to 100 it should find 6 and 28, but for some reason it only recognizes 6 as a perfect number. Why doesn't it output 28? Danke!

Code:
```#include <stdio.h>
#include <stdlib.h>

int check;
int isAFactor(int i, int o);

int main()
{

int startval;
int endval;
int o;//outer loop
int i = 1;//inner loop

int check2 = 0; //if remains 0, no perfect numbers.

printf("Enter starting integer: ");
scanf("%d", &startval);
printf("\nEnter ending integer: ");
scanf("%d", &endval);

o = startval;

for(;o<=endval;o++)
{
for(; i<=o/2; i++)
{
check = isAFactor(i,o);

if (check == 0)
{
}

}

{
printf("\n%d is a perfect number.\n", o);
check2 = 1;
}

}

if(check2 ==0)
{
printf("\nNo Perfect Numbers found between %d and %d.", startval, endval);
}

return 0;
}

int isAFactor(int i, int o)
{
check = o%i;
return check;
}```

2. My guess is that you need to have a valid starting value of 1 for i in this loop.
Code:
`for(; i<=o/2; i++)`
Tim S.

3. When I do that for some reason it doesn't find anything. I think I', asking a bit much, I did put alot of effort and thought in the program. I'll put some more in it :P

4. You also need to reset "add" at some point in your code.

7. Code:
```    o = startval;
for(;o<=endval;o++)
{
for(; i<=o/2; i++)```
The above is a *real bad idea* .... put the initializer for the loop *in the loop*.
What is the value of i the second time through the loop?

I've seen it on here a number of times lately, from a number of different posters.
I sincerely hope there's not some fool teacher out there advocating it!

Code:
```for (o = startval; o < endval; o++)
for ( i = 0; i < o /2; i++)```

8. No, I teach myself. But the reason I did that is for some reason it doesn't work when I put it in there. I'm going to check it out now that it is working.

9. Well, I changed it to while() :S I'll put it in for()'s and see if there is any change

10. changed it to for() it works

Thanks all for your help! it is much appreciated! Sorry for anyone that leeps looking at this post bc of my replies :/