# program doesnt enter function

• 12-17-2008
avisik
program doesnt enter function
hello everyone, i wrote a code in C that suppose to calculate COS of an angle.
i dont need help with the writing, i just have one problem, for some reason the program doesnt enter the function cosApprox, it suppose to enter the function and save the result in sum_column , but it just skips it, does someone knows why?

Thanks.

Code:

``` #include <stdio.h> #include <conio.h> #include <math.h> #define PI 3.1415927 double power(double a, int b); long factorial(int n); double cosElement(double x, int i); double cosApprox(double x, int i); int main() {         double x;  /* Angle variable */         int k;    /* Number of elements variable */         double sum_column; /* Sum of all elements variable */         clrscr();         printf("\nEnter an angle (in Radians):");         scanf("%lf", &x);         printf("\nEnter number of elements:");         scanf("%d", &k);         while(k<0)         {                 printf("Erroneous Input. Please enter number of elements (k>=0):");                 scanf("%d", &k);         }         sum_column=cosApprox(x, k); /* a function to calculate the sum of elements */         printf("The value of Cos(x) is: %.4lf", 1+sum_column);         getch();         return 0; }         double cosApprox(double x, int i)         {                 double sum=0;                 for(i=i;i>0;i--)                 {                         sum=sum+cosElement(x, i);                 }                 return sum;         }         double cosElement(double x, int i) /* a function to calculate the element in the i place of the column */ {         double element;         element=pow((-1),i)*power(x,i)/factorial(i);         return element; }         long factorial(int n)  /* a function to calculate the factorial of a number */ {         long sum_f=2*n;         int i;         for(i=2*n;i>1;i--)         {                 sum_f=sum_f*(2*n-1);         }         return sum_f; }         double power(double a, int b) /* a function to calculate x^2k */ {         double power;         power=pow(a,2*b);         return power; }```
• 12-17-2008
tabstop
It's hard to say why it skips it, given that it does not, in fact, skip the function at all, but instead executes it.
• 12-17-2008
That's God punishing you for your indentation style. :)

Seriously, it's going there - your logic is bad, but it's going there. Math is above my pay grade, but it's stepping nicely right into cosApprox().
• 12-17-2008
avisik
i used the debugger and it totally ignored the function, it just returned a garbage value and didnt enter the function.
• 12-17-2008
You pressed F8, instead of F7.

F8 skips over going into the function. F7 will follow the code, into any function.

Try again, it's going there. I wouldn't lie.

OK, I might lie, but only a little white lie, not a big programming lie.

OK, would you believe I might lie a big black lie, but I'd feel bad about it, and wouldn't do it about programming, anyway.

OK, would you believe ... :) :)
• 12-17-2008
BEN10
yes, Adak is right.the program is entering the function.when i executed the code , it's also giving the answer.for eg,