Line 4: It's a poor practice to name a variable the same as your function. The compiler knows the difference, but it's confusing to the reader.
Line 11: The termination condition of your for loop is wrong. You want <, not >. This is the cause of your subscript out of range.
Line 11: You're incrementing count. Where is count defined? Don't you want to be incrementing your loop variable (i)?
Line 13: That's going to test only if a character is numeric. What if the character is a special character? The isalpha() function is ideal for testing if a character is alphabetic.
http://www.cplusplus.com/reference/cctype/
Line 13: count is undefined. Again, you want your to use your loop variable, i.
Line 13: The test for \n is unneeded. The cin at line 9 will discard the \n.
Lines 15-18: This is going to be repeated for each character that doesn't pass. You really only want to display the message once. Here's a variation on the bool function
pindrought gave you.
1 2 3 4 5 6 7
|
bool IsLetters(const string & input)
{ for (size_t i = 0; i < input.size(); i++)
{ if (! isalpha(input[i]))
return false; // character is not alphabetic
}
return true; // Every character is alphabetic
}
|
Line 18: If the test fails, you input name again, but you don't start testing from the beginning. You start from where ever the previous test failed. i.e. If the third character fails, after inputting the name again, you're skipping characters 0-3.
Line 21: name (the variable) goes out of scope when the function exits. Presumably you want to return name to the caller. How are you doing this?