return value

Hi :)

Why I always got the value return = 0 ??

num is a string number contains binary number begins with the letter "B"
assume num="B10111" i got the return value 0 !!

Help please,,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  if(num[0]=='B') // Check the valid value for binary number
		{
			int length=num.length()-1;
			int che=1;

			while(length!=0)
			{
			    if(num[che]== 0 || num[che] == 1)
			    {
				che++;
				length--;
			     }
				
			     else 
				return 0;
			 }
			  return 1;
		}
Character '0' and '1' is not the same as integer 0 and 1. Put single quotes around the numbers on line 8 and it should work better.
Thanks Peter
It's work now :) :)
Topic archived. No new replies allowed.