# cant figure it out

This is a discussion on cant figure it out within the C Programming forums, part of the General Programming Boards category; i am trying to allow combinations of 3 numbers eg. 222 or 2 numbers followed by a capital letter eg. ...

1. ## cant figure it out

i am trying to allow combinations of 3 numbers eg. 222 or 2 numbers followed by a capital letter eg. 21A. It works fine for the 3 numbers but doesnt accept 2 numbers followed by a letter.

Code:
``` if((u_no[0] > 47) && (u_no[0] < 58))
{
if((u_no[1] > 47) && (u_no[1] < 58))
{
if((u_no[2] > 47) && (u_no[2] < 58))
{
u_count_parts++;
printf("u_no ok\n");
}
if((u_no[2] > 64) && (u_no[2] > 91))
{
u_count_parts++;
printf("u_no ok\n");
}
}
}```

2. Code:
`if((u_no[2] > 64) && (u_no[2] > 91))`
There's a problem there...

3. Code:
```//if first position is a number
if((u_no[0] > 47) && (u_no[0] < 58))
{
//if second position is a number
if((u_no[1] > 47) && (u_no[1] < 58))
{
//if first position is a number or a letter
if((u_no[2] > 47) && (u_no[2] < 58)  || (u_no[2] > 64) && (u_no[2] < 91))
{
u_count_parts++;
printf("u_no ok\n");
}
}
}```

4. Using isdigit() and isalpha() from <ctype.h> will help.

5. is there anything to restrict it to just capitals?

6. Originally Posted by ck1
is there anything to restrict it to just capitals? i have this code now
Code:
```  if((u_no[0] > 47) && (u_no[0] < 58))
{
if((u_no[1] > 47) && (u_no[1] < 58))
{
if((isalpha(u_no[2])) || (isdigit(u_no[2])))
{
u_count_parts++;
printf("u_no ok\n");
}
}
}```

7. Code:
`(u_no[2] > 64) && (u_no[2] < 91)`
From the code i provided above should do it.

or use isupper() from ctype.h