### Problem with isalnum,isdigit,isalpha etc conditionals

First of all, i apologize if this sort of question has already been asked and if i'm being a nuisance but i just don't know what to do.

Alright, so i've been trying to make a car number registration program. I will confess, this is my homework, and i don't expect solutions right away, just some tips and a general direction to what i should do.
It's basically like this:

if the number length is 5/6 where the first 2/3 letters are digits and the rest are letters, it's a valid code (for example "123ABC" or "12ABC") (Estonian car number).

And then there are specially manufactured car numbers with a length limit of 9. And it has to have at least 1 number. (for example "ABCDE12")

Everything else is undefined and are non-compliant with current car number rules etc.

I tried using isalpha, isnum conditionals but i just can't seem to tell the program that i want just the first particular digits etc.

I also tried doing it with for loops, but that didn't work so well.
Then i tried doing it with a while function, that didn't work so well either.

Here's an example of what i tried to do:

 ``1234567891011121314151617181920212223`` ``````#include #include #include #include using namespace std; int main() { int i=0; const int j=3; cout << "Please enter a car number"; string carnum; getline(cin, carnum); if ( (i3])))) printf("This car number is valid (Traditional car number)"); return 0; } ``````

All and any help is appreciated
What exactly you are trying in the above code ? let me try the specially manufactured car function.

 ``123456789101112131415161718`` ``````bool isSMCN(string num) { if(num.length() != 9) { return false; } bool flag = false; for(int i = 0; i < num.length();i++) { if(isdigit(num[i]) { return true; //if any number is digit, its true } } return false; //we are here which means there were no digits. }``````

hope you can try to write other functions like this.
Last edited on
Thank you for responding so quickly, i am currently trying to use this boolean function you posted.

Though i would really like to know, how would i go about telling my if statement to check only 3 first digits and then 3 last digits.
For example:

 ``123456789101112`` `````` string carnumber=123ABC; for(int i=0;i3]) // here i'm trying to tell the if function // check the first letters of carnumber and then check the last 3 letters of //Though i don't know if this is the right way to go about it printf("Valid car number");} ``````
i <= 3 will give either 1 or 0. So, you are actually doing this:

isdigit(carnumber[0]) or isdigit(carnumber[1])

do the same like I did. do two loops, one will run for first three index and other will run for last three index's. See if both the loops satisfy your conditions.
Topic archived. No new replies allowed.