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.
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