Exit was not declared in this scope

Hello everyone,
I'm new to C++ and I was going through some example programs from my textbook involving nested ifs inside loops. I took this program straight from my textbook but for some reason I can't get it to compile. It gives me an error saying the exit was not declared in this scope. If anyone can let me know why this is, it would be a great help. Fyi, idk if it matters but im using Eclipse with mingw.

#include <iostream>
#include <process.h>
using namespace std;

int main() {

unsigned long n, j;

cout << "Enter a number: " << flush;
cin >> n;

for (j=2; j <= n/2; j++)
if(n%j == 0){
cout << "It's not prime; divisible by " << j << endl;
exit(0);
}


cout << "It's prime" << endl;
return 0;
}
The simplest way of knowing whether or not a number is a prime number is to check whether or not the number has exactly two factors.

Just count the number of factors for a number and check.
Topic archived. No new replies allowed.