Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Counter::Increment()
- {
- /*
- Start with the left most (lower most) element of the array and increment it
- Once an element is greater than maxValue, set it to 0 and increment the digit counter
- */
- size_t currentDigit = 0;
- while (currentDigit < maxDigits)
- {
- mData[currentDigit]++;
- if (mData[currentDigit] > maxValue)
- {
- mData[currentDigit] = 0;
- currentDigit++;
- }
- else
- {
- //The incremented digit was less than the max value, so the incrementation was successful. Return true.
- return true;
- }
- }
- //If the code makes it out of the while loop, then "currentDigit" is >= "maxDigits"
- //This means the counter tried to increment a digit that doesn't exist
- //Therefore the counting is maxed out. return false
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement