HELP!

#include <iostream>

using namespace std;
int main()
{
int i,j;
system("cls");

for(i=2 ; i<=541 ; i++)
{

for(j=2 ; j<=i ; j++)
{

if(i % j ==0);

{
if(i == j);
}

cout<<"\t";cout<<i;
break;
}
}



system("pause");
}




//please help me. it just keeps on counting without removing the not prime numbers.what to do? :((
In an if statement, the bit that gets run if the condition is true is the bit BEFORE the semi-colon.

 
if(i % j ==0) /*THIS BIT HERE - NOTHING - IS WHAT GETS RUN, BECAUSE OF THE SEMI-COLON HERE */;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>

using namespace std;
int main()
{
    int i,j;
    system("cls");

    for(i=2 ; i<=541 ; i++)
    {

        for(j=2 ; j<=i ; j++)
        {

            if(i % j ==0);
            {
                if(i == j);
            }

            cout<<"\t";cout<<i;
            break;
        }
    }

    system("pause");
}


The two if statements at lines 15 and 17 don't do anything.
a) there should not be a semicolon at the end of these lines.
b) line 17 has no statements which depend upon it.
Topic archived. No new replies allowed.