Possible Duplicate:
C++ Prime Numbers program
I am working on a c++ program to calculate all prime numbers between 3 and an integer 'x'. When I enter 10 as 'x' I am getting the output: 3 5 5 5 7 7 7 7 7 9
Can anyone tell me how to fix this?
#include <iostream>
#include <cmath>
using std::cout;
using std::endl;
using std::cin;
int main(){
int x;
int i;
int j;
cout << "Please enter an integer 'x' greater than 3: " << endl;
cin >> x;
if (x <= 3){
cout << "Please enter new value 'x' greater than 3: " << endl;
cin >> x;
}
for(int i=3; i<=x; i++){
for(j=2; j<i; j++){
if(i%j == 0)
break;
else if(i == j+1);
cout << i << endl;
}
}
return 0;
}