I'm trying to write code for a menu, that continues to ask for options until you type 'q' for quit. It seemed easy enough, but for some reason only one of my if loops refuses to stop looping even if "continue;" is present. The only way I can get it to stop looping is by using "break;" but then it breaks out of the while loop and I can't keep the menu open. I've tried moving the input before and after inside and outside the for loops to see if that helps, but nothing I try seems to help.
Also, I should mention that it's the ADD if loop that isn't working. The other loops seem to be working fine. Check for case 'a'.
Also, I've tried doing a switch statement as well, but the case 'a' still is the only one that won't stop repeating. Every other case operates once, then breaks and takes in another menu input like it should. Case 'q' ends the menu like it should. It really is just the case 'a' but I can't figure out why.
Does anyone know what I'm doing wrong? I know it must be something silly...
in line 83 or 76 you set "input" to a space which is not equal to 'q', so you are setting yourself up to make it an endless loop. Either remove line 83 or 76 or put it at the top of the loop as input = '\0' as long as "input" is defined as a "char". Although putting it at the top of the loop really does not help as the first thing you would is a "cin" statement.
I've trimmed out all the non-loop functional stuff. All you have to do is put it back.
You've committed one of the 7 deadly sins and combined functions with trying to get the interface loop to work. The best thing to do when that happens is to extract the junk and concentrate on the problem at hand - i.e. getting the loop to do what you want and then feeding that problem solved into the bigger picture.