I'm really not sure why this is not working. It is like the array size is not doubling. I'm sure what I'm missing is something simple, but I can't figure out why it is not functioning properly.
void add_element(int* &array, int &size , int &count)
{
int tempp;
cout << "What number do you want to add ? " << endl;
cin >> tempp;
int temp = size * 2;
int *newArr;
newArr = new int[temp];
if(count == size)
{
for (int i = 0; i < size; i++)
{
newArr[i] = array[i];
}
size = temp;
delete[] array;
++count;
newArr[count] = tempp;
array = newArr;
}
}
See Question&Answers more detail:os