loop to find prime numbers between 1 - 239

I am working on a program in which I must print out the number of primes, including 1 and 239, from 1 - 239 ( I know one and or two may not be prime numbers, but we will consider them as such for this program) It must be a pretty simple program because we have only gone over some basics. So far my code is as such, which seems like decent logical flow to me, but doesnt produce output.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #include <iostream>

using namespace std;
int main()
{
int x;
int n = 1;
int y = 1;
int i = 0;

while (n<=239)
    {x = n % y;
    if (x = 0)
        i++;
    if (y < n)
        y++;
    n++;
    while (i == 2)
        cout << n;
    }
return 0;
}

The way I want this to work is to take n, as long as n is 239 or less, and preform modulus division with every number from 1 leading up to n. Every time a number y goes evenly into n, a counter will be increased by 1. if the counter is equal to 2, then the number is prime and we print it to the screen. Any help would be so greatly appreciated. Thanks
If you use for loops, you can practically translate your English directly to code:
The way I want this to work is to take n, as long as n is 239 or less
1
2
for (int n=1; n<=239; ++n) {
}

and preform modulus division with every number from 1 leading up to n.
1
2
3
4
5
6
7
for (int n=1; n<=239; ++n) {
    for (int factor=1; factor<=n; ++factor) {
        if (n % factor == 0) {
             ...
        }
    }
}


etc.
Topic archived. No new replies allowed.