lundi 22 mai 2017

C++ help validating string input

I have a program where I have to validate the string input for a-z and A-Z and spaces. I also have to remove any extra spaces and i have no idea how to do this on a string.

Here are the professor's instructions:

  1. Loop through the string and validate for a-z or A-Z or . If the name has any other characters, then ask the user to input again, repeat until valid input has been input.

  2. Loop through the string and throw out extraneous blanks, ie "John Allen Smith" should become "John Allen Smith".

I tried the following but it did not work:

for (int x = 0; x < s1.length(); x++)
{
       //c = s1.at(x);
        if (!((c >= 'a' && c <= 'z') || (!(c >= 'A'&& c <= 'Z')))) 
        {
            cout << "error" << endl;
        }
}

Aucun commentaire:

Enregistrer un commentaire