0

Why this code does not give output 2.5

this code is giving output 2.0 instead of 2.5 what's wrong? https://code.sololearn.com/crU2duqvE5dD/?ref=app

26th Jul 2018, 8:00 AM
Dhruvil Prajapati
10 Answers
+ 2
I think because you divide two integers, the answer will be 2. But you specified that it should return a double so it makes it a double by adding the decimal -> 2.0
26th Jul 2018, 8:08 AM
QailBee šŸ¤“šŸ¼
QailBee šŸ¤“šŸ¼ - avatar
26th Jul 2018, 9:47 AM
Dlite
Dlite - avatar
+ 1
Dhruvil Prajapati yes. If you divide 2 integers it will automatically convert the result to an integer
26th Jul 2018, 8:18 AM
ReimarPB
ReimarPB - avatar
+ 1
Dhruvil Prajapati no problem!
26th Jul 2018, 8:19 AM
ReimarPB
ReimarPB - avatar
+ 1
The answer is a double, not an integer. You can input two integers and retur a double, the answer will be different though.
26th Jul 2018, 8:21 AM
QailBee šŸ¤“šŸ¼
QailBee šŸ¤“šŸ¼ - avatar
0
the 2 parameters in your div() function should be 2 doubles
26th Jul 2018, 8:15 AM
ReimarPB
ReimarPB - avatar
0
is it necessary that to take double as a output you have to divide two double inputs???
26th Jul 2018, 8:17 AM
Dhruvil Prajapati
0
okay i get that... thank you
26th Jul 2018, 8:19 AM
Dhruvil Prajapati
0
answer is double because x is declared as a double...answer should be 2.5...
26th Jul 2018, 8:23 AM
Dhruvil Prajapati
0
i tried that, it gives me answer. but i am supposing that dividing two integer should have to give me a double number bcoz i have saved that value in double. Anyway now i know that it's not possible... thanks for your efforts..
26th Jul 2018, 9:59 AM
Dhruvil Prajapati