In this example, you only put a few even numbers into the new array, but you're printing a TOTAL amount of numbers not just the even ones. When your nPozitive is delcared on the stack (and not initialized), it can have ANY values in it.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
You also will need to call "new" on the array for the total.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
I would start out like this:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int nNumber = 0;
cout<<"Enter an amount of numbers: ";
cin>>nNumber;
int* nTotal = new int(nNumber);
int* nPositive = new int(nNumber);
int* nNegative = new int(nNumber);
cout<<"\nNow enter "<<nNumber <<" Numbers\n" <<endl;
for (int i=0; i<nNumber; i++)
{
cout << "Enter number (" << (i+1) << "): ";
cin>>nTotal[i];
}
// code continues here...
Then make a counter to keep track of the positive numbers and one to keep track of the negative numbers.
THOSE will be the amounts you print of each (not the nNumber)
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402