The program is checking every number in the list and should output if is prime or not. Probably I just don't get the prime algorithm right. Currently outputs that no number is prime.
void primList(struct node* stnode)
{
struct node* pr = stnode;
int i;
bool primNum = true;
if (stnode != NULL)
{
while (pr != NULL)
{
if ((pr->num) == 0 || (pr->num) == 1)
primNum = false;
else
{
for (i = 2; i <= ((pr->num) / 2); ++i) //The mistake
if (((pr->num) % i) == 0) //is here?
{
primNum = false;
break;
}
}
if (primNum)
cout << "\n" << pr->num << " is a prime number.";
else
cout << "\n" << pr->num << " is not a prime number.";
pr = pr->nextptr;
bool primNum = true;
}
}
}