1 Attachment(s)
[RESOLVED] How to solve arithmetical problems?
Here is the problem I need to solve:
Attachment 32481
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
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!