0

Using nested loop

The program I working with need to be able to accept an int (which is the answer to problems) separated by new line and then any number of math problems captured in parentheses and separated by a space. I am trying to count the number of operations and can't figure out what is wrong with my loop. When I enter two the following 8 (4+4) (4+4) It gives me 1 and 1 which is the right answer If i add a third problem I get a garbage value for the last index. The strangest part is if I add a fourth value it returns with the correct answer in the final index but that value at [2] is still garbage. If anyone can play with it and help me out I would greatly appreciate it. https://code.sololearn.com/cMGuwB6607Cd

25th Jan 2020, 12:06 AM
Shay Christensen
Shay Christensen - avatar
2 odpowiedzi
+ 1
ok ill try that thx!
25th Jan 2020, 12:58 AM
Shay Christensen
Shay Christensen - avatar
0
You need to initialize all members of "symbolCount" to 0. int symbolCount[wc]; for (int i = 0; i < wc; i++) { symbolCount[i] = 0; ... }
25th Jan 2020, 12:28 AM
Diego
Diego - avatar