C++ (IDE) My switch statement's default case repeats infinitely when triggered, any ideas why?
It's pretty much as explained above. My switch statement has 5 integer cases, which all work fine, but the default statement gets all funky if I input anything that ISN'T an integer. I'll drop the code down below, it's only 50 lines: #include <iostream> #include <cstdlib> #include <ctime> #include <windows.h> #include <stdlib.h> using namespace std; int main() { int input; int difficulty_select = 0; //Selection Screen cout << "CMD RPG \n" << endl; cout << "Select a difficulty to play on. If this is your first time playing, you should try the tutorial first.\n" << endl; cout << "1 > Tutorial\n2 > Easy\n3 > Normal\n4 > Hard\n5 > Legendary\n" << endl; cout << "The # > symbol indicates some sort of choice or command. Input the number to the left of the symbol to select that choice/command.\n" << endl; while (difficulty_select == 0){ cin >> input; switch (input) { case 1: cout << "Tutorial not available at this time...\n"; break; case 2: cout << "Easy difficulty not available at this time...\n"; break; case 3: cout << "Normal difficulty not available at this time...\n"; break; case 4: cout << "Hard difficulty not available at this time...\n"; break; case 5: cout << "Legendary difficulty not available at this time...\n"; break; default: cout << "Input not recognized, or unavailable at this time.\n"; break; } } return 0; } Like I said, all the actual cases work fine, but if I were to input the letter "a" or something, the default case just goes on infinitely. I really don't get it. I put a break there, so the only thing I could think of is maybe the "while (difficulty_selection == 0) { code }" keeps repeating and triggering the default.