Cruicial,
Sorry for any initial confusion, while I was thinking about other parts of your program I missed the fact that an array must be defined with a constant size e.g.,
a[5];
or
a[]{ 1, 2, 3, 4, 5 };
. This way the compiler will know how much space to set aside for the array. The other way to create an array during run time is to create the array dynamically after you get the size from the user. Another option is to create the array as
a[100]{ 0 };
and use
n
to limit how much of the array to use. The initialization of zero will set every element of the array to zero, so if something were to go wrong you will get a zero and not garbage.
Another option is to use a vector whose size can be changed as the program runs. Also there are member functions for the vector class that make working with vectors easier than a conventional array e.g., sort.
When you call the functions pass the array as a parameter.
To the program: each function has code to place a number into the array. That section
1 2 3 4 5 6
|
cout << "Enter" << n << "numbers: ";
for (i = 0; i<n; i++)
{
cin >> a[i];
}
|
should be put in its own function to build the array. Otherwise you are asking the user to provide the same numbers each time one of the functions is called.
In the delete function after I commented out the first for loop it appeared to work fine. Also the searching and sorting functions appear to work, but the insert function I think needs some work. It is hard to understand what to do.
Work on that and let us know if you have any other problems.
Hoe that helps,
Andy