Computer Science Canada

sin button doesnt work

Author:  pari [ Tue May 24, 2011 1:30 pm ]
Post subject:  sin button doesnt work

can someone help me wit my sin button
this what i tried:
VisualBASIC:
    Private Sub cmdSin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSin.Click
        num1 = Double.Parse(txtC.Text)
        txtC.Text = " "
        op = "sin"
        txtC.Text = (Math.Sin(num1) * Math.PI / 180)

Author:  Tony [ Tue May 24, 2011 2:01 pm ]
Post subject:  RE:sin button doesnt work

In what way does this not work?

Author:  Nick [ Tue May 24, 2011 2:34 pm ]
Post subject:  RE:sin button doesnt work

I have two suggestions however I do not know how well either will work, sometimes there's a rounding error when dividing ints and doubles, try dividing by 180.0 instead.

Also I noticed you have brackets around your calculation, I think VB implicitly casts, but just to be sure why not explicitly cast the calculation to string

Author:  z_cross_fire [ Tue May 24, 2011 8:56 pm ]
Post subject:  Re: sin button doesnt work

pari @ Tue May 24, 2011 1:30 pm wrote:
can someone help me wit my sin button
this what i tried:
VisualBASIC:
    Private Sub cmdSin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSin.Click
        num1 = Double.Parse(txtC.Text)
        txtC.Text = " "
        op = "sin"
        txtC.Text = (Math.Sin(num1) * Math.PI / 180)


The last line should instead be:

VisualBASIC:
txtC.Text = Math.Sin(num1 * Math.PI / 180)


The angle must be converted to radians BEFORE using it in the Math.Sin(x) function.


: