Write an algorithm that displays the numbers that have all their digits pair. The numbers will be introduced by the user, the program will end when 0 is introduced.
#include <iostream>
usingnamespace std;
main ()
{
int num, test, digit, impair_digit;
impair_digit=0;
while(num!=0)
{
cin>>num;
test=num;
while(test!=0)
{
digit=test%10; //extract each digit of the number and see if its pair
test/=10;
if(digit/2!=0)//if digit isn't pair add 1 to the counter
impair_digit++;
else
impair_digit=impair_digit;
}
if(impair_digit==0)//if the counter is not 0 then at least 1 digit is impair
cout<<"\n the number "<<num<<" has only pair digits";
else
cout<<"\n the number "<<num<<" doesn't have only pair digits";
}
}
When I run the program, no matter what number I introduce, it always returns that the number introduced doesn't have only pair digits, even if i enter 2222.