#include <iostream> #include<cstring> #include<memory> using namespace std; bool isValid (string customerNumber) { if (customerNumber.length() != 6) return false; for(int i = 0; i < 2; i++) if (!isalpha(customerNumber[i])) return false; for (int i = 2; i < customerNumber.length(); i++) if(!isdigit(customerNumber[i])) return false; return true; } int main() { string cust_number = "AB1234"; cout << isValid(cust_number); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter