Prime numbers

Hello!
Please, how can I prevent the program writing: yes, 0 is prime number?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  bool Prime (const int st) {

for (int i=2; i<st; i++)
if (st%i==0){
return false;
}
return true;


}
int main(){
int a;
cout<<"Type number, please!";
cin>>a;
(a<0)?(a=(-1)*a):(a=a);
if (a==0){a=a+5);
break;}
cout<<a<<endl;
bool b = Prime(a);

if (b==true){cout<<"Yes, it is a prime number";}
else {cout<<"No, it is not the prime number";}
return 0;
}


What I acutally want, is that in the case one types 0, the function Prime is not done.


p.s. as a it writes 5, but in the function "travels" the first a (a=0)???
How to prevent it?


Many thanks!
Change this
1
2
if (a==0){a=a+5);
break;}

to
1
2
3
4
5
if (a==0)
{
   cout<<"No, it is not the prime number";
   return 0;
}
Last edited on
MANY THANKS, IT WORKS!!!!!!.

PLEASE, what means this (translation from c++ to everydays english):

return 0;

on that place, U added?

Last edited on
Topic archived. No new replies allowed.