Hello everyone. I come here with an issue. I'll just refresh your memory if you don't remember the subject of my project; basically I'm working on a chemistry simulator where different reactions can be made. It went good so far, until it came to parsing. To be exact - parsing the coefficients. Note that coefficients are the numbers before the compound, for example, __2__H2O. I'm storing those coefficients in two dictionaries: one dictionary for reactant side, and second dictionary for the products of the reaction. So, when it comes to the reactant side, AKA 2Na + 2H2O -> 2NaOH + H2, the dictionary would return Na: 2, H2O: 2. And it does that. Just one problem: I noticed that the parser doesn't stop when I need it to, that is on the arrow symbol. Instead it proceeds until "Na". Since such element already exists in a dictionary, It simply throws an exception. In order to avoid this I just made an if so when there already is a Key in the dictionary with the same name it would break the loop, but as you might have guessed, it doesn't fix the problem. So, when it comes to the product side of the equation, it actually doesn't add anything to the dictionary. I have no idea what I'm doing wrong (except for the fact that the code is terrible - I will optimise it the moment I finish working on this function).
Code: https://pastebin.com/hQ4KrGNb
Any kind of help will be appreciated.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.