I don't know how to check if a user's input is alphabetic. I want the program to:
- read the user input
- check if it's alphabetic
- output the name again
I tried to use isdigit
and isalpha
but I couldn't get it to work.
//checking if name is valid and not a number
int nameCheck(char enteredName)
{
//if the name is alphabetic
/* return and output it */
//else
/* let the user enter it again */
}
//user enters the name
int nameEntering()
{
cout << "please enter your Name.\n";
char enteredName;
cin >> enteredName;
nameCheck(enteredName);
return 0;
}
int main()
{
char enteredName;
enteredName = nameEntering();
cout << "Have a nice day " << enteredName << "!\n";
return 0;
}
This is my old solution which doesn't work at all. I found that on another site and used it as a "template".
int nameCheck(char enteredName)
{
int i = 0;
char str[] = {enteredName};
while (str[i])
{
if (isalpha(str[i])) printf("character %c is alphabetic\n", str[i]);
else
cout << "Enter your name again without using numbers or other special characters, please!\n";
nameEntering();
i++;
}
return enteredName;
}