My instructor is KILLING me

This is a discussion on My instructor is KILLING me within the C++ Programming forums, part of the General Programming Boards category; Hay gang, Well my instructor has given me this assignment to write code for the Sieve of Eratosthenes algorithim. Never ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    34

    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
    http://members.ebay.com/aboutme/the_ski/

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    34
    Forget it!

    I Found it write after the message posted.

    The Ski

    But hay try this program and see what you think.

    The Ski
    http://members.ebay.com/aboutme/the_ski/

  3. #3
    Unregistered
    Guest
    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

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,747
    > 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
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    that, and even if you did only have 16-bit ints... you could use unsigned...
    hasafraggin shizigishin oppashigger...

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    34
    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.
    http://members.ebay.com/aboutme/the_ski/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having issues with killing suid programs
    By Overworked_PhD in forum Linux Programming
    Replies: 3
    Last Post: 12-13-2007, 08:20 AM
  2. Database assignment is Killing me!
    By Boltrig in forum C Programming
    Replies: 2
    Last Post: 11-29-2007, 03:56 AM
  3. Bush vs. Kerry
    By jlou in forum A Brief History of Cprogramming.com
    Replies: 178
    Last Post: 11-29-2004, 03:45 PM
  4. Killing someones grandparents
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 09-07-2003, 08:56 AM
  5. Killing a process.
    By Brian in forum Windows Programming
    Replies: 7
    Last Post: 01-19-2003, 02:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21