   Local Int Variable Stays 0. (C++ & Math)
  I'm not sure what I have forgotten, but I'm trying to get a percentage of two values that shows the percentage out of a 100. Like blocks spawned and blocks collected overall.Here is my code: int percentage = 0; int SpawnedCars = carSys.ReturnSpawnedSafeCars(); percentage = (carsHit / SpawnedCars)  * 100;ReturnSpawnedSafeCars returns the number of blocks that spawned safely, just if your wondering.I compiled this and debugged it in VS2008 C++. The values still show on the variables in debug mode and I'm not sure if it's the last line.SpawnedCars  = 513carsHit = 311Shouldn't the percentage variable equal 60 then 0 at the end?Thanks, Andrew.   
  It's an integer division.Either use float types, or change the equation around to perform single division at the end (100*carsHit/SpawnedCars).   ;  Yep. If SpawnedCars == 513 and carsHit == 311, then carsHit/SpawnedCars will always be 0, regardless of what type percentage is. Just use floats instead and it will be fine.   ;  Oops, I forgot about floats!Thanks guys works well!   ;  If you want to stick with ints, it's easy enough to just reorder the operations:percentage = (100 * carsHit / SpawnedCars);;  Actually, (a/b)*100 is usually best implemented as:(a*100 + b/2)/b(as that gives you a half-decent bit of rounding).Generally, you want to do division last in any selection of operations.  Use your algebra skills to rearrange things.   ;  That will actually make the case when one of a or b is negative worse thanks to the round-to-zero mechanics of C++.  Plug in a=-3 and b=3 and you'll get -99 with yours, in a case where rounding isn't even necessary.If you want round-to-nearest instead of round-to-zero, it would be properly implemented as ( 100 * a + ((a>=0 == b>=0)?+b:-b) / 2 )/b   