How to count odd and even numbers in rand. array?

I'm trying to count up the number of odd and even numbers (separately) that were randomly generated and stored in a single line array.

Here is my code for this specific function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//Count Odd and Even #'s In Array Function
void evenodd(int t[10], double i)
{
		int odd=0;
		int even=0;
		for(int i=0; i<10; ++i)
{
			if(t[i]%2 = 0)
			++even;

				else
				++odd;
}

		cout << "There are " << even << " even integers in the array!" << endl << endl;
		cout << "There are " << odd << " odd integers in the array!" << endl << endl;

//End Counting Function
}


The problem I am running into is that in line 8 I continue to get an error stating that the t[10] must be a modifiable value.

Can I just declare
 
int h =  t[10]


or am I missing some other part to this?

Thanks in advance!
Last edited on
Seems a common error of using Assignment operator (=) instead of Comparison operator (==)
in which line(s) are you refering to that error of using Assignment operator (=) instead of Comparison operator (==)?
In line 8

if(t[i]%2= 0)
Last edited on
(removed pointless repeat; the % doesn't show clearly within code blocks...)
Last edited on
FYI: You could also write
if( t[i] % 2 == 0 )
as
if( (t[i] & 1) == 0 )
bitwise and, since all even numbers have bit 0 = 0 and all odd numbers have bit 0 = 1
Topic archived. No new replies allowed.