`formula`

, `s1`

, `s2`

, `v1`

, and `k`

are all of type double. You actually don't need all of them to be doubles but you want to make sure the result (`formula`

) is a double and the division **must**be done with doubles. An integer result there will be almost guaranteed to give errant results.

Step two is to beware of equal comparisons with double values ie., testing if

`formula`

is zero. The usual technique for this is to define an epsilon value which means "close enough" and compare with that. Here is an example : C++

const double epsilon = 1.0E-9; // do calculations here double delta = fabs( formula ); if( delta < epsilon ) break;This will break out of the for loop if

`formula`

is in the range between -1E-9 and +1E-9. You can use 1.0E-6 or other values for epsilon as long as it is within your desired computational tolerance.
with the second: Result:0.200000