I need to create a program that accepts a name, to validate that a character and an integer shouldn't be accepted. I made a way to not accept a single character but how can i make a condition to not accept an integer?
#include <cctype> // <--- For "std::tolower() and std::toupper()" + others.
#include <iostream>
#include <string> // <--- Needed for "std::getline()".
usingnamespace std;
int main()
{
constexpr size_t LEN{ 1 };
string name;
do
{
cout << "\n Enter employee name: ";
getline(cin, name);
if (name.length() == LEN)
{
std::cerr << "\n Name needs to be more than 1 letter!\n\n";
}
else
{
cout << "\n You entered: " << name << '\n'; // <--- Used for testing. Comment or remove when finished.
break;
}
} while (true);
// <--- Once a proper length name is entered you can loop through each element of the string to check it for what you need or do not need.
return 0; // <--- Not required, but makes a good break point.