#include <iostream>
#include <iomanip>
usingnamespace std;
void main()
{
int * listDyn;
int max =2;
int n=0;
int i=0;
listDyn = newint[max];
cout << "Enter a list of numbers to be stored in an array. After each entry press ENTER. Enter '-1' when you are finished." << endl;
while( n != -1)
{
cin >> listDyn[i] ;
if( i >= max)
{
max = max*2;
int* TempListDyn = newint[max];
for (int j=0; j<i; j++)
{
TempListDyn[j] = listDyn[j];
}
delete [] listDyn;
int *listDyn = newint[max];
for (int p=0; p<i; p++)
listDyn[p] = TempListDyn[p];
delete [] TempListDyn;
}
n= listDyn[i];
i++;
}
cout << " These are the values you entered" << endl;
for(int k=0; k < i-1; k++)
{
cout << listDyn[k] << " " ;
}
system("pause");
}
The main problem is line 30( commented that line and everything worked perfectly. How do I go about fixing this?
Sorry about the indentation. It looked fine in Visual C++ so I thought it would look fine here. Note to self: Preview before posting is very helpful for everyone involved.