Solution 1 does a good job of fixing all your errors. However, most of these errors wouldn't have been possible if you had used C++ features instead. Here's a different solution that avoids most of the pitfalls you've fallen into:
#include <iostream>
#include <vector>
using namespace std;
pair<vector<int>,vector<int>> PosNeg(vector<int> input_values)
{
std::vector<int> positives;
std::vector<int> negatives;
for (size_t i = 0; i < input_values.size(); ++i)
if (input_values[i] < 0)
negatives.push_back(input_values[i]);
else
positives.push_back(input_values[i]);
return make_pair(negatives, positives);
}
int main()
{
std::vector<int> values;
int n;
cout << "Enter numbers. Enter any character to finish." << endl;
do
{
cin >> n;
if (cin.fail())
break;
else
values.push_back(n);
} while (cin.good());
auto results = PosNeg(values);
cout << "negative values:" << endl;
for (size_t i = 0; i < results.first.size(); ++i)
cout << results.first[i] << " ";
cout << endl;
cout << "positive values:" << endl;
for (size_t i = 0; i < results.second.size(); ++i)
cout << results.second[i] << " ";
cout << endl;
return 0;
}
Improvements compared to the things you did:
1. no need to allocate any array by using std::vector
--> no way to mess up your array deallocation
2. no need to keep track of array sizes by using std::vector
--> no need to determine required array sizes up front
--> no need to pass array sizes into and out of the function
3. can append additional values using vector::push_back()
--> no need to keep track of array index values
--> no way to use incorrect index (yours went out of bounds because you used the input array index for the output arrays as well!)
4. can return the two result arrays as function return by using std::pair
--> no need to specify (and initialize) result arrays before calling the function
--> no need to extend function argument list unneccesarily with output values
--> no way to mess up passing output values by value instead of by reference (you did that)
There are still more things you could do, e. g. using range syntax instead of index values, but that doesn't really improve the program.
I hope this gives you an idea of the usefulness of C++ types such as vector and pair, and gives you an incentive to read up on C++ features so you can use them properly in your future programs.