1. Error Using Math Functions

I am trying to get the standard deviations in my array and the funtions pow() and sqrt() won't work because "error more than one instance of overloaded function pow". Same error with the sqrt.

I've researched it and it has something to do with using integers in the statement. If I caste them as doubles then they work but the results aren't accurate.

If anybody knows how to work around this problems, it would be extremely helpful.

Here is the code I have written so far:

Code:
```void standard (int array[], int numItems, int average)
{
int i = 0, j, n;
int sum = 0, variance;
int hold [1500];

for (i = 0; i < numItems; i++)
{
hold[i] = array[i];
}

i = 0;
n = numItems;

for (j = 0; j < numItems; j++)
{
hold[i] = pow((hold[i] - average),2);
sum += hold[i];
i++;
}

variance = sum / (n - 1);

printf ("\nThe standard deviation is %i\n", sqrt(variance));
}```

2. You should include the declarations for both lib-functions in your code, put
Code:
`#include <math.h>`
at the begin of your sourcefile.

3. I do have that declaration I just didn't include it in the code I pasted

4. Post the full example code.
Make sure, that you use a C compiler not a C++ compiler.

5. I actually was able to figure it out

If I caste the pow as an int and then the hold[i] as a double it works perfect.

Thanks anyways

6. Originally Posted by skmightymouse
I actually was able to figure it out

If I caste the pow as an int and then the hold[i] as a double it works perfect.

Thanks anyways
I can't believe that.
Code:
`printf ("\nThe standard deviation is %i\n", sqrt(variance));`
will print bullsh... and I would listen to BillyTKid and use a c-compiler to compile c-code.
Kurt

7. typecasting is one way to do it, albeit it is not necessary to use floating point (or functions from <math.h>) in your code at all (except when computing the standard deviation).

Code:
```   int temp = hold[i] - average;
hold[i] = temp * temp;```
will achieve the same effect.

For that matter, your code may be made much simpler by not introducing hold as an array.

I'm surprised your code doesn't have problems when printing out sqrt(variance).

8. Sorry, I forgot to mention that I did the same thing with the sqrt() function. Yes this works and I calculated on my calculator to make sure:

Code:
`hold[i] = (int) pow(((double)hold[i] - average),2);`
Same with the sqrt

Code:
`    printf ("\nThe standard deviation is %i\n", (int)sqrt((double)variance));`