/* Prime Number Program Revisisted - Michael Bzdell */ #include using namespace std; /* Function named isitprime that does the logic in determining prime it returns a true / false for whether or not it is prime. It also assigns the divisor value to the variable divisor from the main body of the program. */ bool isitprime (int testinput, int &testdivisor) { bool primebool; for (testdivisor=2; testinput>=testdivisor ;testdivisor++) { if (testinput == testdivisor) { primebool=true; break; } else if ((testinput%testdivisor) == 0) { primebool=false; break; } } return (primebool); } /* Main body of the prime program. Has a few checks for valid entry from the user. Calls the above function. */ int main() { int input, divisor; bool inputreturn; cout << "Welcome to the Prime Program!\n"; input=10000; for (divisor=2; divisor>input; if (input==0) break; if (input<=1) { cout << "\n" << input << " is not a valid entry!!! Try again!\n\n"; input=10000; continue; } if (input==2) { cout << "\n" << input << " is the only even integer that is prime!\n\n"; input=10000; continue; } inputreturn=isitprime(input, divisor); // calls the bool function isitprime if (inputreturn==true) { cout << "\n" << input << " is prime!\n\n"; divisor=2; } else if (inputreturn==false) { cout << "\n" << input << " is not prime! It is divisible by: " << divisor << "\n\n"; divisor=2; } } cout << "Thanks for playing!\n"; system("pause"); }