Pls how do I go about this, I have my input as an integer and my return type as a double but it seems the double have no effect | SoloLearn: Learn to code for FREE!

0

Pls how do I go about this, I have my input as an integer and my return type as a double but it seems the double have no effect

https://code.sololearn.com/cTzjc9yKn96f/?ref=app

5/29/2020 7:31:47 PM

Koder

1 Answer

New Answer

0

A simple example: double d = 1/2; d is now 0 Why? 1 and 2 are Integer, therefore Integer division is executed which results in 0 Fix the problem: double d = (double)1/2 This way d is 0.5 As the first operand is double, a double division is executed.