<p>Why whenever I compile and run the following code in Visual Studio 2008:</p>

<pre><code>double value1 = 10.5;
double value2 = 15.5;
int whole_number = value1 + value2;
Console::WriteLine(whole_number);
</code></pre>

<p>I get an incorrect value of 26 while the answer is 25.</p>

<p>However when I use static casts on the doubles, I get the right answer which is 25.</p>

<p>How can the wrong output be explained?</p>

It's absolutely right.
```
```
double value1 = 10.5;
double value2 = 15.5;
int whole_number = value1 + value2; // int whole_number = 26.0;
Console::WriteLine(whole_number);
```
```
What would you expect instead? The compiler first evaluates the right side, and then implicitly converts to the int. Thus,
```
26.0
```
becomes
```
26
```
When you cast before you add, then you are going to add
```
10
```
and
```
15
```
, which results in
```
25
```
:)