I wanted to get more practice with dynamic array's so I decided to make a fun project. It takes the input until -1 is entered then displays the values entered followed by returned the memory back to the free store.
Is this correct?
Code:#include <iostream> using namespace std; int main(int argc, const char * argv[]) { int n=0; int num=0; int *number=new int[n]; cout<<"Enter and set of values and enter -1 to stop the program \n"; while (num != -1) { cin>>num; number[n]=num; n++; if (num==-1) { for (int j=0; j<n; j++) { cout<<number[j]<<"\n"; } } } delete [] number; return 0; }