Hello, I am currently stuck and unable to get the proper results for my program. Part of the assignment is to count and print all even numbers from an array. I have built my code but just this function doesn't seem to be working right. I am not sure if it's my function call in main that has the problem or the function countEvens itself. When I run this it always shows the count as 0. Please help
remove the return from the for loop and place it before the closing bracket of the function.
1 2 3 4 5 6 7 8 9 10 11 12 13
int countEvens(int arr[], int size)
{
int count = 0;
int evens = 0;
for (int i = 0; i < size; i++)
{
if (arr[i] % 2 == evens)
{
count++;
}
}
return count;
}
Also, to get rid of the other error, which likely has to do with:
resetArray(ar, size);
You still have to write the according function, or delete it entirely, as there does not seem to be any use for it.