Hi I have been trying to use the equation:
int Temp; Temp = 680*((N-82)/(920-82)); return Temp;
It's often possible to re-order the operations to avoid early truncation, without resorting to floating point. Temp = 680*((N-82)/(920-82)); is equivalent to t = N - 82; t = t / (920-82); Temp = 680 * t; The problem is in step 2, where t goes to zero. (Even when N > 920, there's a big loss of accuracy.) Algebraically, it doesn't matter whether you multiply or divide first. So moving the parens to force a different order of operation results in: Temp = (680*(N-82))/(920-82); is equivalent to t = N - 82; t = 680 * t; Temp = t / (920 - 82); The problem to watch out for here is the opposite of the truncation problem. "680 * t" might overflow, depending on the possible input range and size of integers used. Handling overflow is often easy, though -- just use a larger int for those steps -- compared to the expense of floating point or scaling fixed point results.
Try this long Ralph INT Temp Ralph = 680*(N-82); Ralph /= (920-82)); Temp = (short) Ralph return (temp)