Struggling with Trigonometric inputs C# RRS feed

  • Question

  • I just dont know how to figure out what to write or modify in my code to make appear in my tbk1(TextBlock1) the Cos of the input that Ive written in my tbx1 (TextBox1). Pleeeaase Help. Thank you guys.


    Tuesday, January 7, 2014 9:44 AM

All replies

  • Can you show us your code?


    Tuesday, January 7, 2014 11:55 AM
  • The Math.Cos Method takes a double in radians as input and not degrees (or grad).  Other than that, it is a simple function.

    tbk1.Text = Math.Cos(deg_to_rad(Convert.ToDouble(tbx1.Text))).ToString();

    The above code will show the cosine of your TextBox input assuming:

    1. The text in the TextBox is a valid number,
    2. the text is being entered in degrees,
    3. you have written a small "deg_to_rad(double deg)" function to return a double.

    You may also want to look at formatting the output to limit the number of decimal places displayed.

    Beyond this, you will need to clarify your question if you are wanting something else and supply a sample of what you are trying if you are still having problems.

    Tuesday, January 7, 2014 2:38 PM