if (TelephoneNumber != "0000000")
{
while ((strlen(TelephoneNumber) != 7) || (atoi(TelephoneNumber) == 0))
{
cout %26lt;%26lt; "Please enter a valid telephone number!" %26lt;%26lt; endl;
cout %26lt;%26lt; "Please enter the telephone number again: ";
cin %26gt;%26gt; TelephoneNumber;
}
}
outfile %26lt;%26lt; TelephoneNumber %26lt;%26lt; " ";
Using a character array for telephone number. Trying to prevent user from entering alphabets and making them enter exactly 7 characters. But if I use the method above "0000000" will become invalid. When I try to exclude it from the error checking, it doesnt work. How should I do it to make 0000000 valid?
C++ Question Character Array?
Use array of integers to store the telephone number instead of character string.
Reply:Try using a regular expressions to remove all non-numeric characters.
Reply:I'm not sure if this answers your question, but I would use some other test rather than depending on atoi. Use regexp, or simply check each entered character.
I'm not a C++ programmer, so I'm not sure but in C that test at the top to see if the string is 0000000 would not work.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment