Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. bool Counter::Increment()
  2. {
  3.  
  4. /*
  5.  
  6. Start with the left most (lower most) element of the array and increment it
  7.  
  8. Once an element is greater than maxValue, set it to 0 and increment the digit counter
  9.  
  10. */
  11.  
  12. size_t currentDigit = 0;
  13. while (currentDigit < maxDigits)
  14. {
  15. mData[currentDigit]++;
  16. if (mData[currentDigit] > maxValue)
  17. {
  18. mData[currentDigit] = 0;
  19. currentDigit++;
  20. }
  21. else
  22. {
  23. //The incremented digit was less than the max value, so the incrementation was successful. Return true.
  24. return true;
  25. }
  26. }
  27.  
  28. //If the code makes it out of the while loop, then "currentDigit" is >= "maxDigits"
  29. //This means the counter tried to increment a digit that doesn't exist
  30. //Therefore the counting is maxed out. return false
  31. return false;
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement