Style issue:  avoid C casts.      use   `float(total)`   or `static_cast<float>(total)`   instead  `(float)total` 
But I guess you can just keep it as integer and remove the float toatlly.