1. ## need help with program please

This is a lab that i had last week but, i still can't figure it out. Problem: Allow the user to enter positive and negative integers and end the sequence with input of 0. Output the averages of positive, negative, and total integers. If no positive or negative integers are entered then display no positive or negative integers where entered.

ex. Enter a sequence of integers, hit 0 key to stop: 4 4 4 0
The positive average is: 4
There were no negative integers entered
The total average is: 2

My problem is that I can't figure out how to display that there were no positive or negative integers entered. I'm pretty sure that it has something to do with an if statement. Any help would be greatly appreciated. Here's as far I have gotten with my code:
Code:
```int main()
{

int n = 0; // user input
int pSum = 0, nSum = 0, pcount=0, ncount=0;

double pAverage = 0, nAverage = 0, totalAverage = 0; // positive and negative averages

cout << "Enter a sequence of integers, hit 0 key to stop: " ;
cin >> n; // user input
while ( n != 0 )
{
if( n > 0 ) // if input is positive
pAverage = double( pSum += n) / ++pcount; // operation for average
if( n < 0 ) // if input is negative
nAverage = double( nSum += n) / ++ncount;

cin >> n;

}
totalAverage = double(pAverage + nAverage) / 2;

if ( n == 0 ) // end sequence
{

cout << "The positive average is: " << pAverage << endl;
cout << "The negative average is: " << nAverage << endl;
cout << "The total average is: " << totalAverage << endl;

}

else
{
cout << "Invalid integers entered" << endl;// invlaid entry
}

return 0;
}```

2. How is the total average 2 in your above example (4 4 4)?

Anyway, you appear to keep track of positive and negative amounts seperately, so just test if it == 0.

If nSum == 0 then no negative numbers have been entered, if pSum == 0 no positive.

3. Yeah, as the above poster mentioned you are keeping a running total of positive # instances and negative # instances so testing if they equal zero would work:

Code:
```if ( n == 0 ) // end sequence
{
if(pcount == 0)
cout << "No positive integers present" << endl;
else
cout << "The positive average is: " << pAverage << endl;

if(ncount == 0)
cout << "No negative integers present" << endl;
else
cout << "The negative average is: " << nAverage << endl;

cout << "The total average is: " << totalAverage << endl;
}```

How is the total average 2 in your above example (4 4 4)?
Yeah, I'm wondering the same thing... shouldn't the result be 4? Err.. maybe we both misreading the problem or something.

Code:
`totalAverage = double(pSum + nSum) / (ncount + pcount);`

4. Code:
```you can make an int array like

int neg[256];
int pos[256]

when its a negative.
affter parsing the negative number do this.

neg[ncount]=n;

when its a positive.
after parsing the positive number do this.

pos[pcount]=n;

to display shot out a for

for(int i=0;i<ncount;i++){
cout<<neg[ncount]<<endl;
}
for(int i=0;i<pcount;i++){
cout<<pos[pcount]<<endl;
}```
//side note i saw the same thing it shouldnt be 2 it should be 4

5. maybe the total average should be 2 because half way between 0 and 4 is 2
0,1,(2),3,4

i dont know if thats what he ment it might be as he said the total average of the neg and pos numbers?

so if his input was 1,2,3,4,-6,-5,-4,-3,-2,-1,0
then his average would be

-6,-5,-4,-3,-2,(-1),0,1,2,3,4

so the total average would be -1 pos ave 2.5 neg ave -3.5
i have no idea how u would do it if it was ment like this other than
psum/2
nsum/2

ok i just read a bit of your code and this will probly be nothing like what you mean

6. Thanks guys for all your help, yeah i think the totalAverage was suppose to be 4. But, i think Kurisu33 had what i was looking for. thanks man!