Hey guys,

I have a piece of code here that gives the wrong answer

Code:
int a = 5;
float result;
float b = 10;

result = a / b;
The problem was that the result would always be an integer. I cannot understand why this is the case? the variable 'result' is declared as floating point, so why does the integer value 'a' have any affect here? Do most compilers do this or is it only g++

I managed to fix my code by type casting and adding (float) in front of the division. Is there a better, more elegant way of doing this?

Code:
int a = 5;
float result;
float b = 10;

result = (float) a / b;
Many thanks,
James