Moob Ban needs help

When I compile this, i get a string of zeros. Why wont my Array accept the inputs of my for loop?

int main()
{
long long int number;

int factor;
int PrimeArray[1229]={};

for (int n=2 ; n <= 10000 ; n++)
{
for (int f=1 ; f <= n/2 ; f++)
{
if ( n%f ==0)
{
factor++;
}
}
if (factor == 1)
PrimeArray[n-2] == n;
factor=0;
}
for (int m=0 ; m <12 ; m++)
{
cout << PrimeArray[m] << " " ;
}
}
Hey Moobban21,

In the future you need to put your code in the in between the code tags so its easier to read your code and reference line numbers.

I am not sure what your code is supposed to do however, your line if(factor == 1) is almost never true. its outside your second for loop therefore factor gets incremented to a number higher than 1 every time. I think you were trying to put that block of code inside the second for loop. It then might give you some numbers you were hoping for.

Happy Coding
Possibly because there are no "inputs" to your array.

== is comparison, not assignment.

There's a good probability your compiler generates a warning for this. Pay attention to your compiler warnings!

Also, factor has an unspecified value the first time through your loops. Initialize it.

Please read:
http://www.cplusplus.com/forum/beginner/1/
Last edited on
Topic archived. No new replies allowed.