Why doesn't this work, it gives me a syntax error identifier 'factor', I thought I identified factor. If anyone could help me get to where it will compile without errors that would be awesome.
#include <iostream.h>
//Factor(n,k) returns true if k is a factor of n and false otherwise
bool factor(bool n,bool k)
{
if (n%k==0)
return true;
else
return false;
}
//Prime(n) returns true if the number n is prime and false otherwise
//Count_factors(k,b,n) counts the number of factors of the number n from a to b inclusive
bool count_factors(bool k, bool b, bool n)
{
if (k>b)
return 0;
else
if factor(n,k)
return 1+count_factors(k+1,b,n);
else
return count_factors(k+1,b,n);
}
bool prime (bool n)
{
if (count_factors(1,n,n)==2)
return true;
else
return false;
}
void main()
{
cout << prime(10);
cout << endl;
cout << prime(11);
cout << endl;
}



LinkBack URL
About LinkBacks



