• 05-03-2002
cmangel518
Ok, this snippet of code should print 30 prime numbers in ascending order, which it does (code gotten from Borland's Library "Eratosthenes"). BUT it only prints out "1,2,5,7....113" (totally forgets the 3 and the 1 is hardcoded).

if (s==4)
{
RichEdit1->Lines->Insert(0,1);
const int sievesize = 125;
vector<int,allocator<int> > sieve(sievesize, 1);

for (int i = 2; i * i < sievesize; i++)
if (sieve[i])

for (int j = i + i; j < sievesize; j += i)
sieve[j] = 0;

for (int j = 2; j < sievesize; j++)
if (sieve[j])
}

And this snippet of code prints out prime numbers in descending order. BUT it only prints out "113...7,5,3,1" (totally dropping off the 2).

if (s==5)
{
RichEdit1->Lines->Insert(MAX,1);
const int sievesize = 125;
vector<int,allocator<int> > sieve(sievesize, 1);

for (int i = 2; i * i < sievesize; i++)
if (sieve[i])

for (int j = i + i; j < sievesize; j += i)
sieve[j] = 0;

for (int j=sievesize-1; j>0; j--)
if (sieve[j])
}
}

Someone please take a look at this and tell me what I'm missing. Thanks for your help!!!
• 05-03-2002
golfinguy4
Add brackets for your for loops. It makes things clearer and might even solve the problem.
• 05-04-2002
cmangel518
Thanks golfinguy4 for taking the time to answer and try to help out. Well, unfortunately that wasn't the problem...the code was copied straight from Borland's Library except for where I inserted the RichEdit1->..... It was a matter of having the ++ and the -- where it wasn't needed. I guess I just needed to walk away for a bit and sleep on it.

Thanks Again...
Christina