You still need the cast, otherwise the compiler is going to interpret the division as integer division. The divison operator has higher operator precedence than the assignment operator so you're going to do integer division even though the left lside is a float.
TestOne and TestTwo are integers. You add them together you get an integer. You divide that integer by 2 you get an integer. eg. (5+4)/2 = 4, not 4.5
If you want the result to retan the fractional component, you have to cast it to a float before doing the division. (float)(5+4)/2 = 4.5
Do you want the fractional component or not?
If not, then make it an int. As I said before, assignment to an int will drop the fractional component.
If you do want the fractional component, then you better make it a float since only a float will store the fractional component.
Topic archived. No new replies allowed.
You are using a version without Ads of this website. Please, consider donating: