std::string turnsDefined;
std::cin >> turnsDefined;
bool hasPassed;
while(hasPassed != true){
for(char c : turnsDefined){
if(isdigit(c) != true){
std::cout << "Please only use numbers to describe the amount of turns you'd like to do." << std::endl;
hasPassed = false;
break;
std::cin >> turnsDefined;
}else{
hasPassed = true;
}
}
}
I've recently stumbled upon this. I shortened down the code (by a reasonable amount) just so you can try it yourself.
This short program should check if what you enter contains (unwanted) letters. The thing I don't understand: The way I wrote it, I was pretty sure that if I typed something like test2test it's gonna pass (even though it contains letters) just because the if statement will recognize one single number and set hasPassed
to true.
I hope you could make sense of what I wrote. Happy to answer further questions.