
November 10th, 2012, 03:46 AM
#1
Creating C++ program to make a Sine fuction without any library other than iostream?
Hi. I am a beginner in C++ programming. My assignment is to create a C++ Program to find the sine of a number without any library other than iostream by using Taylor Series:
sin (x) = (x/1!)  (x^3/3!) + (x^5/5!)  (x^7/7!) + (x^9/9!) ...... (x^n/n!).
I've spent 45 hours on this but i just cant seem to make it right. I have to submit it within 6hrs.
Here is what i have done till now:
#include <iostream>
double fact (int f); //declaration of factorial function
double power(double x, int y); //declaration of power function
double sin(int x); //declaration of sine function
//double cos(int x); //declaration of cosine function
//double tan(int x); //declaration of tangent function
using namespace std;
int main()
{
float x=0;
cout << "Enter the value of x in Sin(x): " << endl;
cin >> x;
cout << "Sine of " << x << " is " << sin(x);
cout << endl;
}
return 0;
}
//Function for Factorial
double fact (int x)
{
double f=1;
if (x==0)
{
return f;
}
else
for (int i=1; i<=x; i++)
{
f=f*i;
}
return f;
}
//Function for Power
double power (double x, int y)
{
double p=1;
for (int i=1; i<=y; i++)
p=p*x;
return p;
}
//Function for Sin
double sin (int x);
{
double sum_pos = 0;
double sum_neg=0;
double t_sum=0;
for (int i=1; i<=1000; i+=4)
{
sum_pos = sum_pos + (power (x,i) / fact (i));
}
for (int i=3; i<=1000; i+=4)
{
sum_neg = sum_neg + (power (x,i) / fact (i));
}
t_sum = sum_pos  sum_neg;
return t_sum;
}
Please help me. I would be grateful to any sort of help.

November 10th, 2012, 05:30 AM
#2
Re: Creating C++ program to make a Sine fuction without any library other than iostre
Why do your start a new thread with exactly the same problem that is discussed in your previous thread?
Please get back, read what guys wrote you in response to your problem and try to implement what they recommended.
Victor Nijegorodov

November 10th, 2012, 05:35 AM
#3
Re: Creating C++ program to make a Sine fuction without any library other than iostre
Originally Posted by VictorN
Why do your start a new thread with exactly the same problem that is discussed in your previous thread?
Please get back, read what guys wrote you in response to your problem and try to implement what they recommended.
that was some other problem. i cannot use math library and i have to call the function of factorial and power in the function of sine. i dont know how to do that. without using sine function, i can make it work but by using sine function, the program is not compiling. i really need some help here.

November 10th, 2012, 05:54 AM
#4
Re: Creating C++ program to make a Sine fuction without any library other than iostre
Originally Posted by weirdom3
... the program is not compiling. i really need some help here.
What compiler errors do you get?
And, please, edit your post adding Code tags! Have a look at my reply to you in your previous thread!
Victor Nijegorodov
Tags for this Thread
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
This a Codeguru.com survey!
OnDemand Webinars (sponsored)
