When you do something like this s = 1/2 what happens? After the division of 1 by 2(which are assigned to some others variables), the result is put into some temporary variables.Then the value of temporary variable is assigned to 's'.So the value of 's' depends on the value of temporary variable.
Now what should be the data type (int,float etc.) of the temporary variable depends on what your operands(1 and 2 here) are.If one of the operands was double type temporary variable would be double type,if one of the operands was float type temporary variable would be float type,if one of the operands was integer type temporary variable would be integer type,so on.Since at the time of s = 1/2; both the operands are integer the temporary variable becomes integer type. And hence temporary variable contains integer part of the result of 1/2 which is 0.At the time of s= r/2 (where r is float type) one of the operands is float type,so temporary variable is float type and it contains float version of the result 1/2,which is 0.5. Thats why it works this time.But you may also use 'casting' to avoid this type of confusion.