/* isPrime-eof.cpp * tests for primes using an eof-controlled while loop * does not employ a user-defined function * solution for Exercise 1, w1/isPrime-problem.html */ #include using namespace std; int main(){ int n, //input integer pd; //potential divisor //prompt and read n cout << "enter n > 1 (c-d to exit): "; cin >> n; //driver loop while(cin){ pd = 2; //generate and test divisors while(n % pd != 0) pd++; //display result cout << n << ((n == pd) ? "is prime " : "is composite" ) << endl; //prompt and read n cout << endl << "enter n (c-d to exit): "; cin >> n; } //exit cout << endl << "Exiting..." << endl; return 0; }