hello , i want to cin n numbers then to sort the positive numbers in one array, the negative numbers in another array , then to print positive array. So let me explain , i run the program , i enter the 9 , then enter 1 2 3 4 5 6 7 8 -1 , after this it couts me the Positive array , but at the end it prints me some numbers , i have no clue where they came from . I know that there is another way to do that , but i want only with arrays. Help me pls)
#include <cstdlib>
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
int nNumber;
cout<<"Enter a Number"<<endl;
cin>>nNumber;
int nPozitive[nNumber] , nNegative[nNumber] , nTotal[nNumber];
cout<<"Enter "<<" "<<nNumber <<" "<<"Numbers" <<endl;
for (int i = 0; i<nNumber; i++)
{
cin>>nTotal[i];
}
for (int j = 0; j < nNumber; j++) {
if (nTotal[j]>0) {
nPozitive[j] = nTotal[j];
}
else
{
nNegative[j] = nTotal[j];
}
}
for (int k = 0 ; k<nNumber; k++) {
cout<<nPozitive[k]<<endl;
}
getch();
return 0;
}