I have just started learning c++ in the last week and have been having a ball with it. I am, however, having difficulty with a simple prime number generator that i have been working on. I have worked and reworked the relatively easy logic on it and when I run the program through in my head I don't see where the problem is. After you type in a value for y, instead of it returning that many prime numbers it just returns to the next line and does nothing. I don't understand. I am using visual c++ 2010
int main()
{
int y;
int x = 0;
int b;
int a;
bool g;
cout << "How many Iterations? ";
cin >> y;
while (x <= y)
{
++x;
b = 0;
g = false;
while ((b <= x) && (g = false))
{
++b;
a = x % b;
if((b < x) && (b > 1) && (a == 0))
g = true;
}
if (g = false)
cout << x << " ";
}
cin.clear();
cin.ignore(255, '/n');
cin.get();
return 0;
}
holy crap... I knew it would be some tiny detail that I mixed up. It works beautifully now... well is outputting the correct results anyways, just not the correct number of primes per iterations selected although that's easy enough to see why.. Thank you