Question

I want to allow the user to use lowercase or uppercase letters giving the value to the char type variable... Any help??

Was it helpful?

Solution

Err, do you mean something like (where getAChar() is whatever method you're using to get the character):

int ch = getAChar();
while (!isalpha (ch))
    ch = getAChar();

Alternatively, if you want to check that a user enters only alphas. You can get a string with:

cin >> myString;

Checking for alphas is as simple as:

char *cstr = myString.c_str();
for (int i = 0; i < myString.length(); i++)
    if (!isalpha (*cstr++))
        return false;
return true;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top