My code for a main menu isn't functioning correctly. I cant find out why the do while loop repeats forever when the user inputs, a bool is set to true, and it works, but if the user inputs a wrong character, the loop continues forever. and displays "Invalid character. Please try again." and doesn't allow the user to input.
void mainmenu() {
bool wrong = false;
system("cls");
cout << "Hello! Welcome to the menu. ";
cout << "\n\n";
cout << "What would you like to do?\n";
cout << "Options:\n";
cout << "1. Password generator\n";
int choice{ 0 };
do {
cin >> choice;
if (choice == 1) {
wrong = true;
passgen();
break;
}
else {
cout << "Invalid character. Please try again." << endl;
cin.clear();
}
} while (!wrong);
}
Note- I didnt include the #include in this snippet of code, but the error is within the loop repetition.