Dividing contents of 2 dimentional array into one array
Nov 20, 2019 at 1:43pm
Why does my avgHi array output zero if I divide the contents of the two arrays but if I add or subtract them, then I get the correct result?
1 2 3 4
|
for (int i = 0; i < rows ; i++)
{
avgHi[i] = nums[i][1] / nums[i][0];
}
|
Nov 20, 2019 at 1:48pm
Probably integer division.
4 / 8 gives ... wait for it ....0
Nov 20, 2019 at 1:54pm
Thank you. I was able to fix this by adding (float) to one of the numbers being divided.
1 2 3 4
|
for (int i = 0; i < rows ; i++)
{
avgHi[i] = (float)nums[i][1] / nums[i][0];
}
|
Topic archived. No new replies allowed.