halvnumber() c++ code

need c++ code for halvnumber() which recieves an int passed into it, divided by 2 which can be a double.

Can anyone help me?
1
2
3
4
double halvnumber(int i)
{
return (i/2);
}
Last edited on
1
2
3
double halvnumber(int i) {
  return i / 2.0; // Must include ".0", or it won't work
}
why it will not work?
is there any reason?
closed account (z05DSL3A)
1
2
3
4
double halvnumber(int i)
{
return (i/2);
}

would do an integer division
But visual c++ compiler return double without ".0", anyway, thanks for that information
closed account (z05DSL3A)
That is because the result of the integer division is ‘cast’ to double to be returned.
What would be the result of ‘halvnumber(1)’?
yeah, you are right;)
without ".0" it returns 0.000, with it, it returns 0.500
fdsd
Thank you so very much
Topic archived. No new replies allowed.