# User defined cos function

This is a discussion on User defined cos function within the C Programming forums, part of the General Programming Boards category; I am having trouble with this problem. I have attached the assignment. My main problem is understanding what is being ...

1. ## User defined cos function

I am having trouble with this problem. I have attached the assignment. My main problem is understanding what is being asked of me, I must have no idea. My professor told me I must use a loop because we don't know how many terms to use.

Here is what I have for the function (sorry for the cheesy comments we have too):
Code:
```float cosine(float rad, double a)
{
//variable declarations
float t2, t3, t4, t5;

if(-t2<a||t2<a)
{
t2 = 0;
}
if(-t3<a||t3<a)
{
t3 = 0;
}
if(-t4<a||t4<a)
{
t4 = 0;
}
if(-t5<a||t5<a)
{
t5 = 0;
}

}```

2. What part don't you understand?

3. What happens when you test the absolute value and when do you do it?

4. You test it each time you generate a term.

I'm not sure I understand what you mean when you ask what happens. What always happens when you perform a test? If the test succeeds, something happens, if it fails, something else might happen.

Do you know what an absolute value is? Do you know what is meant by “terms”? Do you understand summation notation and the idea of a series? It's very hard to get a grasp of what is confusing you.

5. I think I have the testing the absolute value of the terms down. Maybe I am confused on what a term is and the series.

6. I'd expect calculus to be taught in the same semester as (or before) an introduction to programming, but perhaps not...

Google around for information on summation and series. You don't actually need to know calculus to understand what this question is asking; you just need to learn a little terminology.

7. I am in calculus and I have an A with one month left in the semester so I think the problem is somewhere else. In the program I included I tested the absolute value up to five terms.

8. Instead of having separate variables for t2, t3, t4, t5 write a loop construct that computes 1 the first time through the loop, computes t2 the second time around, computes t3 the third time around, computes t4 the fourth time, computes t5 the fifth time ...... ad nauseum (or at least, until some criterion is met for stopping running around the loop).

9. I see no loop; so I do not think your understanding the problem the same way that I am understanding it. The way I read it it could run many times past the 5 terms you have in your code.

Tim S.

10. Ok I think I am getting close to the objective. I have made this, but it doesn't quite work.
Just my function:

Code:
```double cosine(double rad, double a)
{
int n=2;

{
if(n%2==0)
{
}
else
{
}
n+=2;
}

}```

11. Originally Posted by zfite
Ok I think I am getting close to the objective. I have made this, but it doesn't quite work.
Just my function:

Code:
```double cosine(double rad, double a)
{
int n=2;

{
if(n%2==0)
{
}
else
{