I am creating a very interesting game for a school project, and I am having problems with re-main menu. I created it using a do-while loop , and the problem I am facing is that the menu selection variable is int , and therefore when I (or the user) a non-int by accident, when you select from the menu }while(condition) at the end of the main loop, it cannot be caught, and the program repeats endlessly. Conversely, if you enter an invalid int when selecting a menu, the program will catch it, display the message "invalid input", and then repeat the main menu.
It is difficult to explain in writing what I mean, so here is the source code with the corresponding lines indicated by an asterisk. I save as .cpp and compile on linux using g++ -ansi -pedantic -Wall -Werror . The teacher forbade hardcoding in conditional statements, therefore, global constants.
#include <iostream>
Code Edited regarding current response.
Please let me know if you need more information, thanks in advanced condition!
source share