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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <stdio.h>
#include <string>
#include <ctype.h>
using namespace std;
int main()
{
int i=0;
const int j=3;
cout << "Please enter a car number";
string carnum;
getline(cin, carnum);
if ( (i<carnum.length()) && (carnum.length()<=6) && (isdigit(carnum[i<=3])&&(isalpha(carnum[i>3]))))
printf("This car number is valid (Traditional car number)");
return 0;
}
|
All and any help is appreciated