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
Post a Comment