value = value % 10;
Probably the end-all-be-all of your problems.
If value
is 2034
, then value % 10
returns 4
... and then assigns that value to value
, you go through your if else
block, then do 4/10
get 0
, and exit the while loop
without addressing the other 3 digits.
I suggest something more like this:
while (value > 0) {
if ((value%10)==0) {
zeroCount++;
}
else if (value%2==0) { //As per comment below...
evenCount++;
}
else {
oddCount++;
}
value /= 10;
}
Or, int thisDigit = value % 10
, then replace value
in your current if else
block with thisDigit
.