Argh! HELP!!!

I have a problem, and that is that I cant get this code right, sure I can compile it and run it but the awnser I get is 110 when it should be 120...

// Code start

int XCenter = 160;
int XPos = -50;

float dCubeWidth = XCenter+XPos+((20/100)*50);

// Code END

Whats wrong????
160+(-50) = 110
and
20/100 = 0.20
and
0.20*50 = 10
and
110+10 = 120

isnt that right? or is my calculator broken or something, i use it to controll, but my computer gives me 110...
argh...

Thanks alot, savior!



Comments

  • : I have a problem, and that is that I cant get this code right, sure I can compile it and run it but the awnser I get is 110 when it should be 120...
    :
    : // Code start
    :
    : int XCenter = 160;
    : int XPos = -50;
    :
    : float dCubeWidth = XCenter+XPos+((20/100)*50);
    :
    : // Code END
    :
    : Whats wrong????
    : 160+(-50) = 110
    : and
    : 20/100 = 0.20
    : and
    : 0.20*50 = 10
    : and
    : 110+10 = 120
    :
    : isnt that right? or is my calculator broken or something, i use it to controll, but my computer gives me 110...
    : argh...
    :
    : Thanks alot, savior!
    :
    :
    :
    Just a couple of days ago we had the same conversation: when you planning to get a 'float' or 'double' result you have to tell it to the compiler before the calculation happens:

    20/100 = 0.20 // No it is not, because these are integer constants... the result is zero and remainder is 20.

    20.0/100.0 = 0.20 // Now we talking! You have to use decimal dots to tell compiler that these are 'double' constants...





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion