c++ - invalid operands to binary expression ('double' and 'double') -


// returns random element rho=[0,n-1] based on fitness int roulette_wheel(double fitness[], int n){ double f_sum=0.0, r, f, temp; int k=0; (int j=0; j<n; n++) {     f_sum=fitness[j]; } r=rand()%f_sum+1.0; //(invalid operands binary expression ('double' , 'double')) f=1.0/fitness[k]; while (f<r) {     k++;     f=f+1.0/fitness[k]; }  return k; } 

i don't know why part says invalid operands... thought codes right.

once again, reiterating comments above clarity: you cannot use modulo on floating-point numbers.

a function called fmod(), however, can give remainder of 2 floating point numbers.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -