Help using the sin function?

I need help with a code from my beginner course. This code is to calculate the conductivity of a substance. The formula I am using is lamda = 75βˆ—sin(4.5𝑀)/(350βˆ’π‘‡) where 4.5w should be in degrees. The code I entered should output 0.57 when T=250 and w=11, but the result I keep getting is 0.49. I have no idea why this is happening, any help is appreciated!

1
2
3
4
5
6
7
8
9
10
11
	const double PI = 3.14159265;
	float lam;
	double w, T;
        cout << "Please enter weight percent of beryllium" << endl;
	cin >> w;
	cout << "Please enter the temperature of the substance" << endl;
	cin >> T;
        lam = 75 / (350 - T) * sin(4.5 * w * 180 / PI);
        cout << lam << endl;
        system ("pause");
        return 0;
Last edited on
You are converting to radians incorrectly. It should be:

 
double radians = degrees / 180.0 * PI;

And lam should probably be double.

BTW, you're mixing spaces and tabs for your indentation. That's a no-no! Overall it's probably best to set your editor to insert 4 spaces instead of actual tabs.
Last edited on
4.5w should be in degrees.

Lets say that we have an angle of 180 degrees. The sin() expects radians.

According to your formula, the 180deg is 180*180/PI in radians.
That is 32400/PI, or about 10313 in radians ...

On the other hand we know that 180 degrees is one PI in radians. 3.14, not 10313.
Did everything you said and it's running perfectly. Thank you!
Topic archived. No new replies allowed.