hi im having problems with the return variable of a function returning zero instead of the actual result any ideas?
int keneticEnergy(int num1,int num2){
int KE;
KE=1/2*num1*(num2*num2);
return KE;
}
when i try to display keneticEnergy() on the main function it appears as "0"
1/2*10 is zero
1*10/2 is 5
You should probably be using floats here though.
+1 hamsterman
Not only that, but spell correctly and use meaningful variable names when possible:
1 2 3 4
|
float kineticEnergy( float mass, float velocity )
{
return 0.5 * mass * velocity * velocity;
}
|
The reader of the code (which may be
you in the future), will appreciate it, especially when things get more complicated.
Last edited on