kamito dono kamito dono - 2 months ago 6
C Question

How do I round this int up

Is there any way to round

systemGuess
up. In this case the outcome of
systemGuess
is 5.5 I want it to be 6 how do I do this?

See code below:

int main(void){

int systemGuess = 0;
stystemGuess = (10 - 1)/2 + 1;
printf(" %d ", stystemmGuess);
}

Answer

Use floating point division and ceil:

stystemGuess = ceil((10 - 1)/2.0) + 1;

If you want to round 0.4 down, use round instead.