I have an extract from my code that is supposed to check wheter or not the input given by the user is an integer. If so, the code should go through, if not, the program should jump back/rebegin at a defined point.
again1: // Inloop point 1
cout << " " + player1 + ", where would you like to place a chip? Enter the index (1 - 9).\n" << endl;
int index1; // Initializing index 1
cin >> index1; // Writing input of player 1 into index 1
if (cin.fail()) {
cout << "Error" << endl;
goto again1;
}
Therefore, I would expect my program to ask me again to enter an index if I had tried to give an invalid one before. But if I type e.g. "a" (which is invalid because it's a char), the terminal window just runs my message "Error" hundreds of times in an endless loop and does not jump back to again1.
PS: The goto principle itself works. I have implemented it several other times in the same .cpp
file and it works well.
Any tips?