
Patrick B. answered 10/12/20
Math and computer tutor/teacher
The cast is applied to late, the result will be less than expected for odd sums...
The other part of problem is that the division operator for integers returns only an integer...
To force the coercion, the divisor should be a float...
see the code below
using namespace std;
#include <iostream>
int main()
{
int x=4;
int y=5;
int sum = x + y;
double average = (double) (sum / 2.0f);
cout <<average << endl;
}