Original Post
Seriously, my computer math teacher is pissing me off. Apparently break statements are wrong, when it's the only way that I can make this program work correctly:
"Next time a terrorist gets freed after ten months of red tape, I’ll be sure to thank [the democrats]. I guarantee you that if someone is put in prison with the Patriot Act, even in the rare chance they are not a terrorist or have connections to terrorism, they are sure as hell guilty of something." -- A True Die-Hard American Patriot [edited by - Mscgamer on February 18, 2004 3:00:07 PM]
#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;
int main(int argc, char *argv[])
{
bool divisorFound = false;
cout << "Enter a positive number: ";
int x;
cin >> x;
cout << "\n\n";
for (int y = 1; y <= x; y += 2) // y increases until it is equal to x
{
for (int z = 3; z < y; z += 2) // z increases until it is equal to y
{
if (y % z == 0) // not prime
{
divisorFound = true; // if dat shit ain't prime...
break; // get da fuck outta dat loop, bitch
}
}
if (divisorFound) // if it isn't prime,
divisorFound = false; // reset divisor found
else // if it is prime
cout << y << " "; // print the number
}
system("PAUSE");
return 0;
}
Is there another way to do it without the break statement?
"Next time a terrorist gets freed after ten months of red tape, I’ll be sure to thank [the democrats]. I guarantee you that if someone is put in prison with the Patriot Act, even in the rare chance they are not a terrorist or have connections to terrorism, they are sure as hell guilty of something." -- A True Die-Hard American Patriot [edited by - Mscgamer on February 18, 2004 3:00:07 PM]
Pumpkin Pieman - [