I've seen similar posts to this all around google/stackoverflow. However, I can't find one close enough to my scenario and I don't know C/C++ well enough to port other suggestions over to my methods. Perhaps that's a sign in and of itself...
Regardless, here is my code:
while (true)
{
print("\nSend message, enter command, or \"9\" for help.\n");
if (cin >> input)
{
if (input == TERMINAL_HELP)
{
//Some help code.
}
else if (input == TERMINAL_EXIT)
{
//Some exit code.
}
else if (input < 4 && input >= 0)
{
// Some processing code.
}
else
{
print("Please enter a valid message.");
}
}
else
{
print("Please enter a valid message.");
}
}
The catches works fine for single characters or integers outside of the range [0-4]. But when I put a string in, it gets very weird. It keeps looping through itself infinitely. However after the first time this should be impossible because I do not press enter. It continues through as if it is receiving a blank infinitely.
If you have any suggestions or can point me in the direction of fixing my issue I'd appreciate it! Thanks!
NOTE:
I was trying to follow this, and it worked to some extent. (I got the cin >> input within the if statement idea from this link...) But it does not work to block strings from making the program loop oddly.