#include <iostream>
usingnamespace std;
bool is_prime(int n)
{
for (int i=2; i<=n/2; i++)
{
if (n%i==0 || n%3==0)
{
return 0;//False
}
elseif (n=3)
{
return 1;//True
}
}
}
int main( )
{
int n;
bool result;
cout<< "Enter a number ";
cin>> n;
if (is_prime(n)==true)
{
cout<<n<<" is a prime number"<<endl;
}
else
{
cout<<n<<" is not a prime number"<<endl;
}
}
-W{all,extra,pedantic}
foo.cpp:15:13: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
else if (n=3)
~^~
foo.cpp:15:13: note: use '==' to turn this assignment into an equality comparison
else if (n=3)
^
==
foo.cpp: In function ‘bool is_prime(int)’:
foo.cpp:23:1: warning: control may reach end of non-void function [-Wreturn-type]