hoffnung hoffnung - 1 month ago 11
C++ Question

round down function using floor(c++)

I want to make a simple function that rounds down a double into integer with one condition. If it rounds down to zero, I want it to return 1.

This is what I made.

int Round(double number)
{
int result;
result=floor(number);
if(result=0){result=1;}
return result;
}


But somehow it always returns 0... Any idea whats wrong with my code?

Its done with c++ in visual studio 2010.

Answer

= is used for assignment. Use == for comparison:

if(result==0){result=1;}