### Count even and odd numbers in a random number generator

So I need a program that will say how many even, odd, and "0" numbers there are from a random number generator that generates a set of numbers. I have the generator working fine and i have done programs where a user inputs a set of numbers and it displays the odd and even numbers, but i can not figure out how to make one that actually counts the even and odd numbers and "0's" in a set of numbers from a random number generator. Here is my code for the generator. I feel like maybe there is something simple im missing or i should have done something different with my generator code to make this easier to do. Any help would be great. Thank you.

 ``12345678910111213141516171819`` ``````#include #include #include #include using namespace std; int main() { printf ("The program will generate 5 numbers using a for loop"); srand((unsigned)time(0)); int random_integer; for(int index=0; index<5; index++){ random_integer = (rand()%20)+2; cout << random_integer << endl; } }``````
 ``1234567891011121314151617181920212223242526272829303132`` ``````#include #include #include int main() { const int N = 16'000'000 ; std::cout << "The program will generate " << N << " random numbers using a for loop\n\n" ; std::srand( (int)std::time(nullptr) ) ; int n_even = 0 ; int n_odd = 0 ; int n_zero = 0 ; const int ubound = 20 ; for( int i=0; i
 ``12345678910111213141516171819202122`` ``````#include #include #include using namespace std; int main() { const int N = 100; const int b = 20; int counts[2] = { 0 }; srand( time( 0 ) ); for ( int i = 0; i < N; i++ ) { int r = rand() % b; if ( r ) counts[r%2]++; } cout << "\nNumber: " << N << "\nEven positive: " << counts[0] << "\nOdd positive: " << counts[1] << "\nZero: " << N - counts[0] - counts[1]; }`````` ``` Number: 100 Even positive: 47 Odd positive: 49 Zero: 4```
Topic archived. No new replies allowed.