Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 sin button doesnt work
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
pari




PostPosted: 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)
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue May 24, 2011 2:01 pm   Post subject: RE:sin button doesnt work

In what way does this not work?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Nick




PostPosted: 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
z_cross_fire




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: