My assignment is to create an array of 25 random integers, ranging 1-100. It also has to tell me how many how many numbers (EVEN only) that are printed in the random array. I've done most of the work, but my program keeps saying that I have 0 even numbers. Any suggestions?
#include<iostream>
#include<ctime>
usingnamespace std;
void printArray(constint a[],int size);
void fillArray(int a[], int size);
int countEvens;
int main()
{
srand((unsignedint)time(0));
int ar[25];
fillArray(ar, 25);
printArray(ar, 25);
return 0;
}
void fillArray(int a[], int size)
{
for (int i = 0; i < size; i++)
a[i] = rand() % 101;
}
void printArray(constint a[],int size)
{
for (int i = 0; i < size; i += 1)
cout << a[i] << endl;
{
for (int i = 1; i <= 25; i++)
i = i + 1;
cout << "There are " << countEvens << " even numbers in the array." << endl;
}
I didn't notice that I deleted the variable for int countEvens;
I realize with programming, you must pay attention to every single detail. Thank you for your help :)