void load(int *n, double *x, double **arr, bool randomize) { *arr = (double*)malloc((*n + 1) * sizeof(double)); srand(time(NULL)); for(int i = 0; i <= *n; i++) { if(! randomize) { scanf("%lf", *arr + i); } else { *(arr + i) = rand(); } } }
Based on the randomize parameter, I want to fill the array with random or arbitrary double numbers. However, this code does not compile; it displays "invalid conversion from int to double" in another section.
Replacing rand() with any floating point value, such as 5.0, means that it is not possible to convert double to double instead.
(double) rand() or (double) 5 cause similar errors.
*n , of course, is read earlier in this function, I just turned it off here.
What could be wrong here?
source share