# prime numbers

• 10-20-2008
xbusterx
prime numbers
Code:

``` #include <iostream> using namespace std; int main () {   int j;   int t;   int p;   int num;   cout << " Please enter an even integer greater than 2: ";   cin >> num;   for ( int i = 2 ; i < num; i++ )       if  ( ( i == 2 ) or  ( i % 2  != 0  ) )   {         p = i;       }   {         for ( int j = 2; j > p; j++ )             if ( p % j != 0 )     t = p;         cout << t << endl;       }   return 0;   }```

I'm using this program to give me the prime numbers that are less than the number entered, but it's not working?
• 10-20-2008
master5001
Are you asking me? Or is that a statement? Because if you are asking me, I will simply ask why do you use an artificial code block around a for loop?
• 10-20-2008
tabstop
Quote:

Originally Posted by xbusterx
Code:

``` #include <iostream> using namespace std; int main () {   int j;   int t;   int p;   int num;   cout << " Please enter an even integer greater than 2: ";   cin >> num;   for ( int i = 2 ; i < num; i++ )       if  ( ( i == 2 ) or  ( i % 2  != 0  ) )       {         p = i;       }   {   for ( int j = 2; j > p; j++ )       if ( p % j != 0 )         t = p;   cout << t << endl;   }   return 0;   }```

I'm using this program to give me the prime numbers that are less than the number entered, but it's not working?

With indentation matching your code, maybe you can see how your program logic is not what you intended it to be.
• 10-20-2008
xbusterx
Quote:

Originally Posted by master5001
Are you asking me? Or is that a statement? Because if you are asking me, I will simply ask why do you use an artificial code block around a for loop?

Ya I'm asking you what would u do?
• 10-20-2008
master5001
Code:

```#include <iostream> using namespace std; int main (void) {   int j;   int t;   int p;   int num;   cout << " Please enter an even integer greater than 2: ";   cin >> num;   for ( int i = 2 ; i < num; i++ )     if  ( ( i == 2 ) or  ( i &#37; 2  != 0  ) )     {       p = i;     }   {     for ( int j = 2; j > p; j++ )       if ( p % j != 0 )         t = p;     cout << t << endl;   }   return 0; }```
• 10-20-2008
xbusterx
Quote:

Originally Posted by master5001
Code:

```#include <iostream> using namespace std; int main (void) {   int j;   int t;   int p;   int num;   cout << " Please enter an even integer greater than 2: ";   cin >> num;   for ( int i = 2 ; i < num; i++ )     if  ( ( i == 2 ) or  ( i &#37; 2  != 0  ) )     {       p = i;     }   {     for ( int j = 2; j > p; j++ )       if ( p % j != 0 )         t = p;     cout << t << endl;   }   return 0; }```

that doesn't do any this.
• 10-20-2008
tabstop
That's the point he's making -- the braces (in red) don't do anything. So why did you put them there?
• 10-20-2008
master5001
Dude, I just repasted your code so human behings who aren't freaks like me and tabstop can spot the problem from a mile away.

Are you doing what you are meaning to do, here? I am thinking it does not look like you meant to do this at all.

Just press CTRL+A then DEL in your IDE. That should relieve the problem using some built in functionality of most modern IDE's... unless you are using eMacs or something.
• 10-20-2008
xbusterx
Quote:

Originally Posted by master5001
Dude, I just repasted your code so human behings who aren't freaks like me and tabstop can spot the problem from a mile away.

Are you doing what you are meaning to do, here? I am thinking it does not look like you meant to do this at all.

Just press CTRL+A then DEL in your IDE. That should relieve the problem using some built in functionality of most modern IDE's... unless you are using eMacs or something.

i'm using emacs.
• 10-21-2008
cpjust
Quote:

Originally Posted by xbusterx
i'm using emacs.

Ouch. I'm sorry to hear that. :p
• 10-21-2008
master5001
Lol its ok. I was just in a bad mood yesterday. I was giving you the shortcut keys to delete the whole source. Which wouldn't be very helpful to you at all.

I don't mind using eMacs. It makes me feel more computer nerdish when I do (yeah, I know... I am weird like that).

Back on topic; I am looking at your code and thinking that bracket belongs like this:

Code:

```#include <iostream> using namespace std; int main (void) {   int j;   int t;   int p;   int num;   cout << " Please enter an even integer greater than 2: ";   cin >> num;   for ( int i = 2 ; i < num; i++ )   {     if  ( ( i == 2 ) or  ( i &#37; 2  != 0  ) )     {       p = i;     }     for ( int j = 2; j > p; j++ )       if ( p % j != 0 )         t = p;     cout << t << endl;   }   return 0; }```