I'm working on an exercise for pointers. I'm supposed to calculate the primes from <= x. Inside of my FOR loop I get the "expression must have integral or enum type" error. I think it has to do with i being an int and x being a double. I've tried a lot of things and nothing seems to make it work.
int pi(double x)
int * numprimes;
numprimes = new int;
// Declare pointers and allocate memory for all of them
// Compute number of primes <= x and store at integer that
// numprimes points to.
int count = 0;
for (int i = 2; i <= x; i++)
if (x % i != 0)
*numprimes = count;
int ret = *numprimes;
// Deallocate memory for all pointers declared
If you want to try excersizes on pointers try solving simple problems like swapping array elements etc. i don't understand as to why you need the pointer in the above program it is completely unnecessary. Also primes are natural numbers not fractions.