I created a simple bit of code that should solve your problems. https://onlinegdb.com/4QPjzcJbz. I made the code as self - explanatory as I could.
Hope this helps,
When you fail to read something from std::cin, the input is not consumed, the buffer still contains data. Trying to read again will try to read the same invalid data (e.g. characters, when you're looking for digits) and that's why you end up with an infinite loop.
To fight this, you need to
Please, see your fixed code below:
bool valid = false;
int operation = 0;
while (valid == false)
std::cout << std::endl << "\tEnter choice: ";
if (!std::cin >> operation) // Did reading from std::cin fail?
std::cin.clear(); // Clear the error flag
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // Ignore anything until the new line character
if (operation >= 1 && operation <= 4)
valid = true;
std::cout << "\tInput range is from 1 to 4 only." << std::endl;