+ 3
How can we add the condition: "neither letters nor spaces nor symbols allowed"?
I'm trying to have the user input a string of any five numbers. (a) If it is indeed five numbers, the output should be true. (b) If there are letters, special symbols, operators or spaces (anything other than numbers), the output should be false. https://code.sololearn.com/caMoa3LDC22t/#cpp I was thinking of perhaps adding some != conditions to address (b) in line 86 of code. What is an all-inclusive condition that could be used? Or should some kind of function be used instead?
2 Respostas
+ 2
You know the size of the string, if it is 5 characters long and you also counted 5 digits then it must be correct :)
This function might also be helpful. http://www.cplusplus.com/reference/cctype/isdigit/
+ 1
using std::regex and std::match
https://code.sololearn.com/cpdAj8MVKHh5/#cpp