Hey Guys so I'm trying to make some sort of encyclopedia of Pokemon (Pokedex) I'm in the early stages of it. I'm trying to prevent numbers being input instead of names. So heres what I have so far. so far i've put the int variable and some if statements but to no luck. Thanks!!
int x =3 ;
cout<<"what is your favorite Pokemon?:" << endl;
// I'm trying to say if you type in a name then you get "What a great Pokemon!"//
cout<<"What a great Pokemon!";
/* I'm trying to say if you type in any number or symbol other than a name then you get
"You twat don't even try it or i'll kill you!"*/
cout<<" You twat don't even try it or i'll kill you!";
I'm trying to prevent people from putting numbers or other character instead of a name.
Well, you need to be very specific about what you mean by a "name". For example could it contain spaces or a hyphen? May it contain a numeric character or an apostrophe?
In the code below, I've simply checked that every character is a letter of the alphabet, but that may not be sufficient for Pokemon. A simpler approach would be to check only the very first letter. On the other hand a more advanced version might hold a complete list of all acceptable names, and check that the user's input was found in that list.
cout << "what is your favorite Pokemon?:" << endl;
cin >> pokemon0fname;
// Check that every character is a letter of the alphabet
bool nameIsValid = true;
for (unsignedint i=0; i<pokemon0fname.size(); i++)
nameIsValid = false;
cout<<"What a great Pokemon!" << endl;
cout << "that isn't a name" << endl;