+ 1

Does anyone know why this code always returns 0 ?

This is a simple linear function https://code.sololearn.com/cfukJ8ine050/?ref=app

1st Oct 2019, 3:59 AM
Meysam _PHOENIX
Meysam _PHOENIX - avatar
3 Respostas
+ 3
(1/2)*x =0*x =0 When both operands of the division are integers, the result is an integer division which produces the quotient. Adding the decimal point makes it a floating point literal: (1.0/2.0)*x or x/2.0
1st Oct 2019, 4:29 AM
jtrh
jtrh - avatar
+ 3
add a type cast to this line like this: double y=((double)1/2)*x;
1st Oct 2019, 4:23 AM
Anton Böhler
Anton Böhler - avatar
+ 1
Thank you . Solved
1st Oct 2019, 4:32 AM
Meysam _PHOENIX
Meysam _PHOENIX - avatar