jeudi 12 mars 2015

Limiting area codes in phone number entered


I have the following code:



int main()
{
char text[81];
cout << "Enter phone number:";
cin.getline(text, 81);

char numbers[15] = { " 0123456789()-" };

int size_of = strlen(text);


int counter = 0;

for (int a = 0; a<size_of; a++)
{
for (int b = 0; b<14; b++)
{
if (text[a] == numbers[b])
{
counter++;
}
}
}

if (counter == size_of)
{
cout << "Phone number is valid";
return 0;
}

else
cout << "Phone number is invalid";
return -1;

int stop;
cin >> stop;


}


There is no problem with the code itself, but i'm just stuck on how I can limit the valid phone numbers to a certain set of area codes. For example only the area codes 555 246 and 131 are allowed.




Aucun commentaire:

Enregistrer un commentaire