The problem is one of scope. You got variables named
i
and
z
appearing 2 times in the main. Once at the top of the function and again inside the do/while loop.
The problem is that your while condition is checking the values of the first 2,while the code inside the inner loop is working with the second 2.
To fix it, remove the declarations that are inside the loop and initialize the first
i
to 0.
#include <iostream>
using namespace std;
main()
{
int c[100];
int z, i=0;
do{
cout<<"Please enter number(-1 to end)"<<endl;
cin>>z;
if(z!=-1)
{
c[i]=z;
}
i++;
} while(z!=-1 && i<100);
cout<<"the total number of positive integers entered"<<i-1;
}