Error message

I am trying to make an error message for every negative number its used but i cant do that can someone help me please, thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  #include <iostream>
using namespace std;
 
int isPrimeNumber(int);
 
int main() {
   bool isPrime;
   int count;
   cout<<"Enter the value of n:";
   cin>>count;
   for(int n = 2; n < count; n++){
       isPrime = isPrimeNumber(n);
 
       if(isPrime == true)
          cout<<n<<" ";
   }
   return 0;
}

int isPrimeNumber(int n) {
   bool isPrime = true;
 
   for(int i = 2; i <= n/2; i++) {
      if (n%i == 0){
         isPrime = false;
         break;
      }
      int isPrimeNumber(int n) {
      	if(n < 1) {
      		cout<<"Negative numbers are not allowed!";
		  }
	  }
   }
   return isPrime;
}
Why are you defining a function named isPrimeNumber inside another function with the same name?
I dont know what i did here but the code works fine without the error message but i need it so i cant make it work thats why i need help. :/
Topic archived. No new replies allowed.