Hi, I am having an issue with a switch statement i was hoping someone could maybe help out with. The input i wish the user to give is a number, and when this is done, the switch works fine, however, when a letter is given, the default statement prints, but rather than just printing the once, like I thought it would, it repeatedly prints, and does not stop.
When you try to read letters as a number the stream "goes bad" and needs to be "cleared" before it can be used again. You also need to get rid of the letters since they will have been left in the buffer.
This still allows a number followed by a letter, like "1a", which will cause switch case 1 to execute and then the next cin will read (choke on) the letter. To deal with that it's best to read the input as an entire line first, then, using an istringstream, read the integer and ensure the line is blank after that.