#include <iostream>
usingnamespace std;
int main()
{
constint MaxR = 3;
constint MaxC = 3;
int sum = 0, test, compare1; //test = the value divided by 2, compare1 = multiply test by 2 to see if it's the original value, if yes, add.
int arr[MaxR][MaxC] = {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }};
for (int i = 0; i < MaxR; i++)
{
for (int k = 0; k < MaxC; k++)
{
test = arr[i][k] / 2;
compare1 = test * 2;
if (arr[i][k] == compare1 * 2)
{
sum = sum + arr[i][k];
}
}
}
cout << sum;
system("PAUSE");
return 0;
}
Well. If you would have debugged your code, you would have realized that the if statement is never true. That's now how you check whether a number is even or odd.