So I made all the functions for a project where I was supposed to take input from the user through a menu and make an array and do various things with it. Two things I couldnt figure out were how to Lock and unlock the array, and then I also couldnt figure out how to delete the array without getting an error. Here is the code:
int addamount();
void addvalues(int arr[],int n);
void showvalues(int arr[], int n);
int sumvalues(int arr[], int n);
void avervalues(int arr[], int n);
void showmax(int arr[], int n);
void showmin(int arr[],int n);
int menu(int size,int choice,bool hidemenu);
int main()
{
int size=0;
int choice=0;
int *parr= new int[size];
bool hidemenu=true;
for(;;)
{
choice=menu(size,choice,hidemenu);
if(choice==1)
{
size=addamount();
}
else if(choice==2 && size != 0)
{
addvalues(parr,size);
hidemenu=false;
}
else if(choice==3 && hidemenu==false)
sumvalues(parr, size);
else if(choice==4 && hidemenu==false)
avervalues(parr, size);
else if(choice==5 && hidemenu==false)
showmax(parr, size);
else if(choice==6 && hidemenu==false)
showmin(parr, size);
else if(choice==7 && hidemenu==false)
showvalues(parr, size);
else if(choice==8 && hidemenu==false)//SUPPOSED TO LOCK
const int (*parr);
else if(choice==9 && hidemenu==false)//SHOULD DELETE arr
delete[]parr;
}
return 0;
}
The error I get after hitting delete says the application wrote to memory after the end of the heap buffer. The const doesnt lock the array but doesnt give me an error. Any ideas of why this isnt working and what else I could do would be great.