First off all your loop for determining whether the number is prime or not is not correct. You always will get that the number is prine because the last iteratiion of the loop tries to divide a by a-1. And as result is_prime will be set to true.
Also instead of using the comparision operator (==) you use the assignment operator (=) in the following statement
Thanks for the advice. The logic behind my code is:
1) Input number eg: 10
2) Divide number by every number till x-1 eg: Divide 10 by 2, Divide 10 by 3.......Divide 10 by 9 .
3)If there are remainders every time you divide, Number is Prime
else
Number is not prime.
Can someone show me how the coding should be like?? Big Thank you in advance
int x;
bool is_prime = true;
cout << "Enter a number:";
cin >> x;
for ( int i = 2; i <= x / 2; i++ )
{
if ( x % i == 0 )
{
is_prime = false;
break;
}
}