March 28th, 2014, 02:34 AM
[RESOLVED] How to solve arithmetical problems?
Here is the problem I need to solve:
Here is the code I created in order to solve it:
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.
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();
March 28th, 2014, 08:51 AM
Re: How to solve arithmetical problems?
You are grouping wrong. Multiplication and division precede addition and substraction.
When having doubts with this sort of problems, reduce your expression to chunks of the ecuation.
result = (Math.Pow(numx, 2) + Math.Pow(numz, 2)) / (1 - (Math.Pow(numx, 2) - Math.Pow(numz, 2)) / 2);
Hope it helps. Good luck!
A = X^2 + Z^2
B = X^2 - Z^2
C = B / 2
D = 1 - C
E = A / D
result = E
Last edited by Nikel; March 28th, 2014 at 08:53 AM.
Reason: Just formatting.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!