### Count

In this program I need to count the amount zeroes but I think I got it but every time I run it, it goes into a infinite loop. What am I doing wrong?

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364`` `````` const int MAXSIZE =100; /* Function Prototypes */ void readdata(int [], int); int countzeros(int[], int); void append(int [], int); int main() { int number[MAXSIZE]; int a, n; cout<<"Enter the number of elements in the array: "<>n; for(int i=0; i>vals[i]; cout<
 Inside your countzeros function your position variable never changes its value so it will never be greater than n.

I get what you're saying, but being a little slow as I am today, I have no idea what to do.
I was wrong about that, it does change, I was the slow one, below is what I think is wrong.

remove line 12 and 42, put line 42 in line 12.

I think in this statement the second parameter should be 'n', not 'a':

 `` `` ``countzeros(number, a);``

in line 25 replace with this:

 `` `` ``cout << countzeros(number, n);``

Last edited on
I did it. But it doesn't show how many zeroes are in the array in fact, it just says "The amount of zeroes in this array are: " and that's it. I want to be able to show the amount of zeroes that I put in the array.
You are calling the function but you aren't actually printing out the value it returns, change it to something like this.

` cout<< "The amount of zeroes in this array are: " << countzeros(number, a) <<endl; `

You are also passing it the variable 'a' which doesn't ever seem to be assigned to anything.
here it shows how many zeros the user inputs.
did you replace the line 25?
Topic archived. No new replies allowed.