Reputation: 1
if (c % 3 == 0)
{
d=d+1;
}
else
{
cout << "The number has no digits divisible with 3" << endl;
}
But the thing is, c
was used before in a while structure because I had to use it to calculate the sum of the number's digits and other things.
If I try to write this outside of the while, I believe c
will get the value only of the first digit of the number because of the loop. I tried giving the value o c
to another variable but it's still the same.
Upvotes: 0
Views: 68
Reputation: 31204
Maybe you should try putting your logic in another while
loop, similar to the one you used before.
You can also try calculating the number of digits divisible by 3 in the same loop that you calculate the sum in
while(...)
{
...
sum = sum + c;
if(c%3 == 0)
{
d = d+1;
}
...
}
Upvotes: 1