user1050632 - 10 months ago 85

C Question

Working on computing the geometric mean of values in an array

The function should compute the geo mean correctly, but i'm getting a weird error message

`#include <stdio.h>`

#include <stdint.h>

#include <math.h>

extern "C"

double geomean(double myarray[], int count) ////error here, expected '(' before string constant

{

double geomean = 1;

double root = (1/(double)count);

int i;

for(i = 0; i < count; i++)

{

geomean = geomean * myarray[i];

}

geomean = pow(geomean, root);

return geomean;

}

Answer Source

`extern "C"`

is not valid C (it's only valid in C++). Just remove it if you're working in pure C.