Write your question here.
Hi guys, as the title states, I'm trying to create a program that takes string as an input, searches through it, and checks whether or not if the parentheses are "balanced" e.g. "({})" or "[]()".
Once the program is run, strings two and three are displayed as "Not balanced!" which is what I was expecting. However, string one is not displaying any result at all. If I were to comment out isBalanced for two and three, nothing would appear.
Can anyone please explain the reason behind this? I'm aware there are solutions for this particular problem but I'm really more interested in the mistakes I made and how I can improve my code.
I'm new to programming and with the C++ language, so I apologize if my question seems a bit silly. Thanks :)
for (int i = 0; i < x - 1; i++)
This will skip the last char in the string
if (mstack.top() != s[i])
It will always be true if you have anything but an opening brace.
It also would be better of isBalanced would return a bool and you do the output in main.