As part of a homework assignment my program has to have a function which will carry out Simpson's method for integration. Anyway my function is given here:

Code:

double function1(double a, double b, int N)
{
double result;
double functerm;
double funca = sqrt(1+pow(a,4));
double funcb = sqrt(1+pow(b,4));
int count = 1;
double x=a+((b-a)/N);
printf("%g\n",funca);
printf("%g\n",funcb);
while (x<b)
{
if(count%=2 == 0)
functerm+=2*(sqrt(1+(x*x*x*x)));
else
functerm+=4*(sqrt(1+(x*x*x*x)));
x+=((b-a)/N);
count++;
}
printf("%g\n",functerm);
result=(functerm + funca + funcb)*((b-a)/(3*N));
return result;
}

When used with the values a=-1, b=1 and N=4, the values for funca and funcb give correct answers, however the result of functerm is a massive number (in the order of 10^238 or something) when it should be about 10. Can anyone spot where my mistake is being created?

The formula for Simpson's rule was given on a sheet by the way, as neither myself nor my maths student friends seem to remember it as its given there.