1. ## dividing Doubles

What Approach is there to cout the elements in this array that are even
I have already got an idea but no yet complete

Code:
```double d_array[10] = {3.4, 12.8, 9.5, 2.0, 1.7, 3.8};

for(int i=0; i<6; ++i)
if(d_array[i]%2==0)
cout<<d_array[i];```

I know this produces an error but i also know its in the right direction, if somebody can shed some light on this would be greatly appreciated;

2. Only integers can be even. So you need to check if an element is an integer before you check if it is even. Then you need to cast the element to an integer to apply &#37;.

3. is 12.8 even or odd?

4. a non-integer number has simply no even/odd parity.

int(12.8) is even

5. Originally Posted by yukapuka
What Approach is there to cout the elements in this array that are even
Code:
`double d_array[10] = {3.4, 12.8, 9.5, 2.0, 1.7, 3.8};`
Only the 4th element is even, everything else is a floating point number and as such is neither odd nor even.

QuantumPete

6. Code:
```if(fmod(d_array[i], 1.0) != 0.0) {
// not an integer
} else if ((((int) d_array[i]) &#37; 2 == 0)) {
// even integer
} else {
// odd integer
}```
This assumes all your integral doubles are representable with infinite precision ( < ~2^50), and fits in an int.

7. But of course you can define your own parity for doubles with a given precision (!), by simply considering only the first decimal value for example.

8. Only integers can have parity, regardless of whether the number can be represented as an integer without loss of precision. even the element 2.0 is nto even because it is by definition not an integer, but a double. parity only has meaning in the context of interger arithmetic. Its like saying whats the remainder of 5.7 divided by 3.14.

9. Its like saying whats the remainder of 5.7 divided by 3.14.
2.56? What's wrong with that?

Only integers can have parity, regardless of whether the number can be represented as an integer without loss of precision.
What I meant is they can be converted to integers and then have their parity checked.

10. Originally Posted by abachler
Only integers can have parity, regardless of whether the number can be represented as an integer without loss of precision. even the element 2.0 is nto even because it is by definition not an integer, but a double. parity only has meaning in the context of interger arithmetic. Its like saying whats the remainder of 5.7 divided by 3.14.
By that logic int(2) is not an integer either, because int has finite bounds. The type the programmer uses to encode a number need not relate to the type of number it represents.

As for the mathematics, I'm pretty sure that integers are defined to be a subset of reals. As such 2.0, which represents a real number, is equal to 2 the integer. But regardless of the formal semantics, there is something particular that the OP wants to do. Even if it is technically incorrect to describe the process as finding the even numbers doesn't change what the OP wants to do.