You can use bool cin.fail() to check if cin >> x was successfull (it won't be for non-integers, since x is int).
Look up cin.clear and cin.ignore functions, as these will come in handy when dealing with looped cin statement.
the problem now is, whenever I input, for example two letters, it will output
"No. Enter a NU" two times. is it possible for it to be just one? anyway it solved what I wanted. thanks again!
You can use ignore with parameters specifying how many character to ignore or at which particular character to stop ignoring:
- std::numeric_limits<std::streamsize>::max() - is formal way of saying "As much as it fits inside cin buffer"
- '\n' - is read as: "or when encounter newline" - which happens after pressing Enter.
In full, the line looks like: std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');