0

这应该比较简单。

是)我有的:

int progress; // iteration we are on, starts at 0, always incr by 1
int percentage; // from 1 - 100, starts at 0
int percentage_trip; // derived from total_results / 100
int total_results; // lets say its 200 (note that it can be anything, like 939049)

我需要的:

在上面的示例中,每次进度达到 2、4、6、8 等时,百分比整数应增加 1(即百分比++;)

我的想法围绕着格式非常糟糕的嵌套 IF 语句展开,我正在寻找正确的方法。

4

1 回答 1

3
int incrementAmount = total_results/100;
if (progress % incrementAmount) { percentage++; }
于 2012-10-12T19:55:28.833 回答