Probably something else in your code that makes it zero. Perhaps casting to an int?
There is integer division here:
49 + 91 + 100 + 43 = 283. (int)
int → 283/400 ← int = (int) 0.
You need to perform actual floating point division:
float ac=(79+91+100+43)/400.0f;
Weird that I never knew also... But I found the solution is this:
float ac=(float)(79+91+100+43)/400;
Last edited on