Reputation: 43
I have no Idea what is wrong. I have converted my sin answer to degrees but It will not give me the correct answer but instead gave me a 4.18...... The correct output should have been around 2.8.
Input 1 = 4.9 and Input 2 = 35 On my calculator Sin(35) * 4.9 = 2.8....
output = Convert.ToDouble(Input1.Text)
* Math.Sin(Convert.ToDouble(Input2.Text)*180/Math.PI);
Upvotes: 2
Views: 112
Reputation: 4408
Math.Sin()
takes the angle in radians.
What you do are doing here
Math.Sin(Convert.ToDouble(Input2.Text)*180/Math.PI)
is converting input2 to degrees.
You need to multiply by Math.PI/180
to convert degrees to radians.
Edit: So you should use
Math.Sin(Convert.ToDouble(Input2.Text)*Math.PI/180)
Upvotes: 4
Reputation: 22323
As has been stated in other answers, your operator precedence is backwards, you need to divide Math.PI by 180 rather than dividing 180 by Math.PI. So, your function should be:
output = Convert.ToDouble(Input1.Text) * Math.Sin(
Convert.ToDouble(Input2.Text)*(Math.PI/180));
Upvotes: 0