Having Trouble with sin and cos

Here is my code so far
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Multiple Angle Trig Identity
// A program to verify or falsify a formula
// Alex Wild
// Engr 21
// 9/19/2011

// Psuedocode
// 1. Establish variable x and character f
// 2. Ask user for a number for x
// 3. Calculate the equations
// 4. Use if/else statment to tell user if it is true.
// 5. Hold window open

#include <iostream>
#include <cmath>
using namespace std;

int main ()
{
	// Establish variable x and character f

	int x;
	char f;

	// Ask user for a number for x

	cout << "This program will establish whether the equations:" << endl;
	cout << "cos 5x = (16cos^5 (x) - 20cos^3 (x) + 5cos (x))" << endl;
	cout << "tan 5x = (5tan (x) - 10tan^3 (x) + tan^5 (x)) / (3-tan^2 (x) + 7tan (x))" << endl;
	cout << "Are true for the given value of x, Please choose a value for x:" << endl;
	cin >> x;

	// Calculate the equations

	if((cos(5*x)) = (16*pow(cosx,5)) - (20*pow(cosx,3)) + (5*cos(x)))
	{
		cout "Equation 1: True" << endl;
	}
	else
	{
		cout << "Equation 1: False" << endl;
	}
	
	cin >> f;

	return 0;
}

The objective is to have the user give you a value of x and with the value of x the program tells you whether the statement is true or false. Am I going about his right I get an error that says im not using cosine right. help would be greatly appreciated.
closed account (zb0S216C)
On line 35, the = is performing an assignment operation, not comparison. Instead, change it to ==.

Wazzak
I changed it to a == but it is still complaining about my sins and cosines.
http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_goldberg.html

Also, you have some syntax errors, like pow(cosx, 5) //what is cosx?
Okay I fixed the syntax errors I think but I am not fully understanding that paper? =/ sorry
here is my code now and was wondering why the sin and cos problems are occuring?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Multiple Angle Trig Identity
// A program to verify or falsify a formula
// Alex Wild
// Engr 21
// 9/19/2011

// Psuedocode
// 1. Establish variable x and character f
// 2. Ask user for a number for x
// 3. Calculate the equations using if/else statment to tell user if it is true.
// 4. Hold window open

#include <iostream>
#include <cmath>
using namespace std;

int main ()
{
	// Establish variable x and character f

	int x;
	char f;

	// Ask user for a number for x

	cout << "This program will establish whether the equations:" << endl;
	cout << "cos 5x = (16cos^5 (x) - 20cos^3 (x) + 5cos (x))" << endl;
	cout << "tan 5x = (5tan (x) - 10tan^3 (x) + tan^5 (x)) / (3-tan^2 (x) + 7tan (x))" << endl;
	cout << "Are true for the given value of x, Please choose a value for x:" << endl;
	cin >> x;

	// Calculate the equations using if/else statment to tell user if it is true.

	if((cos(5*x)) == (16*pow(cos(x),5)) - (20*pow(cos(x),3)) + (5*cos(x)))
	{
		cout << "Equation 1: True" << endl;
	}

	else
	{
		cout << "Equation 1: False" << endl;
	}

	if((tan(5*x) == (5*tan(x)) - (10*pow(tan(x),3)) + (pow(tan(x),5))) / (3 - (pow(tan(x),2)) + 7*tan(x)) 
	{
		cout << "Equation 2: True" << endl;
	}

	else
	{
		cout << "Equation 2: False" << endl;
	}
	
	// Hold window open

	cin >> f;

	return 0;
}
Last edited on
You can't test floating point numbers for equality like that. If you think about it, you'll realise they'd have to have exactly the same bit pattern for the comparison to be true, but with floating point numbers, you're almost certain to not see that.

You have to check if they're within some range of each other. What range should you use? You use the precision of the floating point type.

Now, you use int everywhere, but if you look at sin and cos, you'll find they work on type double. So you need to check within the precision of type double.
Thank you!!!!!!!!!!!!!!!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Multiple Angle Trig Identity
// A program to verify or falsify a formula
// Alex Wild
// Engr 21
// 9/19/2011

// Psuedocode
// 1. Establish variable x and character f
// 2. Ask user for a number for x
// 3. Calculate the equations using if/else statment to tell user if it is true.
// 4. Hold window open

#include <iostream>
#include <cmath>  // Used for formulas, so we have the right tools
using namespace std;

int main ()
{
	// Establish variable x and character f

	double x;
	char f;  // Character used to keep window open at the end of program

	// Ask user for a number for x

	cout << "This program will establish whether the equations:" << endl;
	cout << "cos 5x = (16cos^5 (x) - 20cos^3 (x) + 5cos (x))" << endl;  // Equation 1
	cout << "tan 5x = (5tan (x) - 10tan^3 (x) + tan^5 (x)) / (3-tan^2 (x) + 7tan (x))" << endl;  //Equation 2
	cout << "Are true for the given value of x, Please choose a value for x:" << endl;
	cin >> x;  // x-value we will be using to verify

	// Calculate the equations using if/else statment to tell user if it is true.

	if(cos(5*x) == (16*pow(cos(x),5)) - (20*pow(cos(x),3)) + (5*cos(x)))  // Compares both sides of equation for given x value
	{
		cout << "Equation 1: True" << endl;  // If they are equal this will appear
	}

	else
	{
		cout << "Equation 1: False" << endl;  // If they are not equal this will appear
	}
	
	if((tan(5*x) == (5*tan(x)) - (10*pow(tan(x),3)) + (pow(tan(x),5))) / (3 - (pow(tan(x),2)) + 7*tan(x)))  // Compares both sides of equation for given x value
	{
		cout << "Equation 2: True" << endl; // If they are equal this will appear
	}

	else
	{
		cout << "Equation 2: False" << endl;  // If they are not this will appear
	}
	
	// Hold window open

	cin >> f;

	return 0;
}

TA-DA =]
Topic archived. No new replies allowed.