[RESOLVED] How to solve arithmetical problems?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: [RESOLVED] How to solve arithmetical problems?

  1. #1
    Join Date
    Mar 2014
    Posts
    1

    [RESOLVED] How to solve arithmetical problems?

    Here is the problem I need to solve:

    Name:  A9_R218_C.jpg
Views: 126
Size:  10.4 KB

    Here is the code I created in order to solve it:

    Code:
    double numx, numz, result;
                numx = Convert.ToDouble(textBox1.Text);
                numz = Convert.ToDouble(textBox2.Text);
                result = Math.Pow(numx, 2) + Math.Pow(numz, 2) / 1 - Math.Pow(numx, 2) - Math.Pow(numz, 2) / 2;
                label1.Text = result.ToString();
    But when solving the problem manually I get different answer, so what I'm doing wrong? A help would be appreciated and thanks for your time in advance.

    Kind regards,

    Ron

  2. #2
    Join Date
    Jun 2011
    Location
    Buenos Aires, Argentina
    Posts
    110

    Re: How to solve arithmetical problems?

    You are grouping wrong. Multiplication and division precede addition and substraction.
    Code:
    result = (Math.Pow(numx, 2) + Math.Pow(numz, 2)) / (1 - (Math.Pow(numx, 2) - Math.Pow(numz, 2)) / 2);
    When having doubts with this sort of problems, reduce your expression to chunks of the ecuation.
    Code:
    A = X^2 + Z^2
    B = X^2 - Z^2
    C = B / 2
    D = 1 - C
    E = A / D
    result = E
    Hope it helps. Good luck!
    Last edited by Nikel; March 28th, 2014 at 09:53 AM. Reason: Just formatting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center