I'm working on a program to practice dynamic arrays. What I'm trying to do is have the user input numbers to fill an array that will double in size when it gets full. When the current array is full, the filled array should be copied to a temporary array, then deleted. A new array with double the size of the previous is then created, and then the values of the temporary array should be copied to the newly created array. The temporary array is then deleted, and the process should be repeated until the user inputs 0. When the user inputs 0, the program should display all the the numbers recorded in the array.
I'm doing something wrong, but I'm not sure where it is or how to fix it. I can only input 2 values before I get an error message saying "Debug Assertion Failed!". Even if I only input one number, when I input 0 to display the array I get long numbers that mean the elements don't exist.
Could anyone point me in the right direction as to what I need to do and/or what I'm doing wrong?
You also don't delete[] Dynarray after you output it at 60-63. Also, the if statement on 58 is completely pointless; the code could not have exited the while loop if input was not 0, so that if is unconditionally going to be entered as things are.
This is more of an efficiency point, but you could simply allocate TempDynarray is being the original array with *2 the size, copy Dynarray over, delete[] Dynarray, then simply set DynArray to point to the same array as TempDynarray. This saves you from having to copy all the elements back again.