I wrote a program to factor trinomials in the format "x^2 + bx + c" to "(x + a)(x + y) but it crashes after giving the factor outputs. Any help in fixing the crash is greatly appreciated :)
Line 13: int x=1;
declares an int variable called x, value 1
Line 16: int i[x];
declares an array of 1 place (since x = 1) --> This is strange, reflects perhaps some misunderstandings of what arrays are and how they behave.
Lines 39, 41, 42, 43, 45, 48, 56, 59, 62, 65, etc.
use variables to reach cells of the array. Remember the array was declared as having 1 cell? That's probably the problem. If in any case you end up evaluating an expression like: i[2]; i[10];
or anything beyond: i[0];
you'll be in trouble.
Yes it is. Arrays can't grow in size. You declare them as having a specific number of cells and that's what they get. The problem comes when you try to reach a place in memory beyond the array's borders: C++ will let you do that, and the program will crash (in almost every case). You are in charge of doing some bound checking before trying to evaluate an array cell.
What you are thinking of (an array capable of resizing during the execution of the program -runtime) is called vector. It's very similar, but it has a LOT more to give.