# Odd/Even Digits in a Number-Help!

• 02-27-2002
ProgrammingDlux
Odd/Even Digits in a Number-Help!
Hey everyone, I need some help doing this ..i got most of the source code, but there's a little problem. When I input a three digit number, sometimes it'll tell me that the digits are odd/even/mixed when i know they're not.

1 Example:
input> 333
"Digits are Mixed(odd and even)" <THIS is wrong

2 Example:
input>222
"All Digits are even" <This is right

3 Example:
input>123
"Digits are Mixed(odd and even)" <this is also right

What could be the problem in my code...Take a Look Please
#include<iomanip.h>
main()
{

int Num, Dig1,Dig2,Dig3,Val1,Val2,Val3;

cout << "Please enter a 3 digit number and Press
Enter : ";
cin >> Num;
cout<<Num<<endl;

Dig1=Num/100;
Val1=Dig1%2;
Dig2=Val1/10;
Val2=Dig2%2;
Dig3=Val2/1;
Val3=Dig3%2;

if((Val1==0) && (Val2==0) && (Val3==0))
cout<<"All Digits are Even";
else if((Val1>0) && (Val2>0) &&(Val3>0))
cout<<"All Digits are Odd";
else
cout<<"The Digits are Mixed (Odd and Even)";

return 0;
}

Thanks for taking a look
• 02-27-2002
paultwang
// ...
Dig1=Num/100;
Val1=Dig1%2;
Dig2 = (Num-Dig1*100)/10; // here.
Val2=Dig2%2;
Dig3 = (Num-Dig1*100-Dig2*10); // here.
Val3=Dig3%2;

// ...
• 02-27-2002
ProgrammingDlux
Thanks Bro
Thanks a lot I appreciate your help.. damn i love this site!