On 9/14/07, Jim Dougherty <[EMAIL PROTECTED]> wrote: > [email protected] wrote: > > aot=1/2*b*h; > > Equvilent to > > aot = 1/(2*b*h); > > > > That why your ans is 0.00000 > > > > Your can try this > > aot = b*h*1/2; > > > > This is bad advice. > > 1/2*b*h is NOT equivalent to 1/(2*b*h) > > Division and multiplication are of equal precedence. > If you want to add parenthesis to make the order of operations clearer then: > > 1/2*b*h is equiv to ((1/2)*b)*h > > The answer is 0.0 because (1/2) is integer division whose result is 0. > > To correct your problem do one of the following: > > aot = 0.5*b*h; > > or > > aot = b*h/2;
Simple thumb of rule I've always followed: (1) Cast all variables in a statement to same type (2) Always use parenthesis to mark each token even when not required, it makes life much easier for someone else who's going to maintain your code, and easy to understand on editors like VS where you can navigate between parenthesis using CTRL + ] Cheers - Ananth
