I have an assignment to write a code that will ask for a licence plate and in return will answer whether it is a regular, a custom or incorrect. Since I live in Estonia, where regular plates are 3 or 2 numbers followed by 3 letters and custom plates have up to 9 characters where there has to be atleast 1 number and 1 letter.
What I am having trouble with is: How can i make the program count the numbers and letters separetly from a line?
For example i ask for a licence plate and the user enters 851TFF and it should understand that it's a regular and give the respective answer, but if something random is inserted or it goes over the limit like 854 then it would say that it is invalid.
std::string line; //Declare variable called line of type of std::string
std::cin >> line; //Read input from user into line variable
int digits = 0; //Create counters
int letters = 0; //For different kind
int other = 0; // of symbors
for(char c: line) { //Loop for each symbol in line
if(isdigit(c)) //If currend symbol is a digit...
++digits; //...increase number of digits
elseif(isalpha(c)) //If it is a letter...
++letters; //Increase amount of letters
else //If it is not a digit or a letter
++other; //Then it is some other symbol
}
//Now in digits variable we have amount of digits, number of letters in letters, and other symbols in otherif (other != 0) //Output message if there is anything aside from digits and letters in entered License Pate
std::cout << "junk symbols in plate number";