HELP with simple code needed

I having problems getting the correct answer. forceB =400,lengthAC=8,lengthAD=6 when I check I get the correct answer for ForceDC and Ay but when I solve for shear I should get 0 but I get -2.8. WHY
1
2
3
4
5
6
7
8
9
10
11
12
  double ForceDC, Ay, shear;
	
UpdateData(true);
	
ForceDC = (m_force_B * (m_lengthAC/2)) / ((m_lengthAD/(sqrt((m_lengthAD*m_lengthAD)+(m_lengthAC*m_lengthAC))) * m_lengthAC));
	
Ay = m_force_B - (m_lengthAD / (sqrt((m_lengthAD * m_lengthAD) + (m_lengthAC * m_lengthAC))) * ForceDC);
	
shear = Ay - (m_force_B * 1/2);
	
m_display = shear; 
	UpdateData(false);
Are these are defined as floating point numbers? It's actually giving a very small number for shear = -2.84217e-14.

If you define shear as an integer or cast the result of the calculation to integer you'll get the result of 0 that you expect.
i want the answers as a double because I want to be able to change the values and still get the correct answer and an integer rounds to much.
The accuracy of floating points can be a little off. Your result with these values is this -0.0000000000000284217.

You could use fixed and setprecision() in <iomanip> to determine how many decimal values of a result you want to display.

cout << fixed << setprecision(2) << "shear = " << shear << endl;

shear = -0.00
I'm working with an MFC application so that code doesn't work, do you known which works with an MFC.
Topic archived. No new replies allowed.