First of all, here is the code:
When I run the program, no text goes on the screen. (Okay, sometimes the prime numbers between 0 and 200 does) But, I just get a screen saying "primenumbers.exe has encountered an error and needs to close." One of those Windows errors. This was under windows XP. Compiled with MinGW C++ compiler under Code::Blocks IDE.Code://primenumber.cpp //exercise 2, chapter 3, feb 19, 2008 //Prints out prime numbers with nested for loops #include <iostream> using namespace std; int main() { cout << "All prime numbers between 0 and 200.\n\n"; bool primeNumber = false; for (int i = 0; i < 200; i++) { for (int j = 0; j < i; j++) { if ( ( i % j ) == 0 ) { cout << i << " is not a prime a number."; primeNumber = true; break; } if (!primeNumber) { cout << i << " is a prime number." << endl; } } } cout << "\nThere they are!\n" << endl; return 0; }



LinkBack URL
About LinkBacks


