从0到N计数

Moh*_*ete -4 c++ loops

我有一个计数器,最多可以递增一个数字。但它不是从0开始。它是从1开始。

for(int i = 0; i <31; i++ )
{
     my_count.incrementCounter();
     my_count.printCounter();
}
Run Code Online (Sandbox Code Playgroud)

在增量计数器中

if (currCountVal < maxCountVal - 1)
{
    currCountVal++;
    overFlow = false;
}
else
{
    overFlow = true;
    currCountVal = 0;
}
Run Code Online (Sandbox Code Playgroud)

在printCounter中

{
    cout << currCountVal << endl;
}
Run Code Online (Sandbox Code Playgroud)

我希望输出应从0开始,但应从1开始。

Pau*_*ans 7

在您的for循环中:

 my_count.incrementCounter();
 my_count.printCounter();
Run Code Online (Sandbox Code Playgroud)

打印之前先进行递增,所以当然它将是1而不是0。