My instructor is KILLING me

• 11-10-2001
TheSki
My instructor is KILLING me
Hay gang, Well my instructor has given me this assignment to write code for the Sieve of Eratosthenes algorithim. Never heard of that? That makes 167,000 of us as well. Anyways, You do not have to know it but, I just need help trying to figure out why I have a parse error at end of input when I go to compile. Here is my code:

//
//
//
//
//
// This program is uses the Sieve of Eratosthenes algorithim to calculate the prime numbers
// between 1 and 50,000.

#include <iostream.h>
#include <iomanip.h>

const int arsize = 50001;

using std::cout;
using std::cin;
using std::endl;

int main()
{

int num1, num2, count, count1, count2, num4, x1, y1, z1;
int num3[arsize];

for ( x1 = 1; x1 <= arsize; x1++ )
num3[x1] = 1;

cout << "Calculating the Prime Numbers between 1 and 50000...." << endl;

num3[0] = 0;
num3[1] = 0;
for ( y1 = 2; y1 <= (arsize / 2); y1++)
{
if ( num3[y1] == 1 )
{
count = 50000;
for ( z1 = 2; z1 <= arsize; z1++)
{
if ( num3[z1] == 1 )
{
num4 = z1 % y1;
if ( num4 == 0 )
{
num3[z1] = 0;
count--;
}
}
}
}
}
cout << count << " prime numbers found!" << endl;

cout << "Now, enter a lower boundry and an upper boundry (interger values only, please)" << endl;

cout << "Now, enter a lower boundry and an upper boundry (interger values only, please)" << endl;
cout << "and I will print all of the prime numbers between those boundries." << endl;
cout << endl;
while ( num2 < num1 )
{
cout << "Please enter the lower boundry (between 1 and 50000): ";
cin >> num1;
while (( num1 < 1 ) || ( num1 > 50000 ))
{
cout << "Please enter the lower boundry (between 1 and 50000): ";
cin >> num1;
}
cout << "Please enter the upper boundry (between 1 and 50000): ";
cin >> num2;
while (( num2 < 1 ) || ( num2 > 50000 ))
{
cout << "Please enter the lower boundry (between 1 and 50000): ";
cin >> num2;
}
if ( num2 < num1 )
cout << "Your upper boundry number cannot be smaller then your lower boundry." << endl;
}

cout << "Here are all of the prime numbers in the range of " << num1;
cout << " to " << num2 << ", one per line:" << endl;
for ( int count1 = num1; count <= num2; count++ )
{
if ( num3[count1] = 1 )
{
cout << count1 << endl;
count2++;
}

return 0;
}

Any suggestions to help this amature?

Thanks The Ski
• 11-10-2001
TheSki
Forget it!

I Found it write after the message posted.

The Ski

But hay try this program and see what you think.

The Ski
• 11-10-2001
Unregistered
Just a quick point, you are storing up to 50000 right.
I think the maximum value you can store in a signed integer is 32767:

so const int arsize = 50001 is to much
• 11-10-2001
Salem
> I think the maximum value you can store in a signed integer is 32767:
Only in old 16 bit DOS compilers

Most 32 bit compilers have 32 bit ints
• 11-10-2001
doubleanti
that, and even if you did only have 16-bit ints... you could use unsigned...
• 11-10-2001
TheSki
Well I just finished the program and it will go to 50,000 indexes. I am using a Linux system to program and compile. Like I said, my instructor is killing me. Thanks Gang for your input.