1) Get rid of your global variables. 99.99 % of the time, a global variable is a sign of bad design.
2) Let's be kind and assume that your code is
not indented like it is in the post, and that the layout style is the result of cut&paste weirdness. If it
is indented as show here, then for goodness sake, take a look at some of the indent styles
here[
^], choose one you like, or some variation thereof and stick with it.
3) Add some
meaningful comments to your code -
particularly if you are posting it to a web site for assistance. In the long run this will help you later on if you need to come back to this and are trying to remember what's going on. In the short term, it will help those of us that are willing to look at the code a clue as to what it is the code is
supposed to be doing.
4) provide a concrete example of what input is causing your issue. The information you've provided here doesn't give me any clue as to what your program is expecting and what's going wrong.
5) If at all possible, reduce the code to the bare minimum that produces the error or unwanted behavior. For the most part, 150 lines of code is more than most of us are willing to wade through to find what went wrong. Ideally, if you can narrow down the problem to maybe less than 50 lines, then there's a better chance someone will actually look at it.
6) In this case, maybe give some clue as to how to exit the program! The user and/or tester should not have to abort the program to get it to stop. Maybe add some prompt to let the user know that input is expected?
7) Research how to use the debugger for your system. There will probably be ways to examine the contents of STL containers, but you may have to do some work to find do so. Google is your friend. Probably someone here can help with how to examine the contents of a stack if they know what your programming environment is.
8) Ultimately, you can use normal output routines to help show what your code is doing. It might get ugly, but you could write a
print_stack()
function that will print the contents of the stack. Don't forget that you can't iterate over a stack, so you will need to create a copy before you print it. This can be accomplished most simply by not using a reference as the function's argument. You can then call your stack print routine at strategic places in your code to show you what the stack looks like. Since you have
stack<int>
,
stack<char>
, and
stack<string>
this might be a good time to look into template functions. You should be able to write a single template print_stack() function that will handle any stack type.