Jimmyt1988
Jimmyt1988

Reputation: 21126

My calculation function is not returning anything?

My function is returning 0?

int ResizeLockRatio( int width, int height, int desired )
{
    int returnValue = ( height / width ) * desired;
    return returnValue; // returns 0?
}

int lockedRatioHeight = ResizeLockRatio( 1920, 1200, 1440 );

Any ideas?

Upvotes: 0

Views: 75

Answers (1)

taocp
taocp

Reputation: 23624

 int returnValue = ( height / width ) * desired;

you are doing integer divide, truncated to 0 sometimes.

You are passing width = 1920, height = 1200, so height/widht =1200/1920 integer divide will truncate to 0 in this case.

EDIT: you may try to first do multiplication then do division according to "Caption Obvlious":

int returnValue = ( height * desired ) /width ;

Upvotes: 3

Related Questions