0

Why is this output wrong?

I'm trying to make a converter by using class and object. There's no error message but the output is not what i expected. https://code.sololearn.com/c3B2CRF7AUX6/?ref=app

21st Aug 2019, 6:41 PM
khoirul Hadi
khoirul Hadi - avatar
4 Respostas
+ 1
remove spaces before () jarak.setMil(10); jarak.getmil() jarak.getkilmet() jarak.getDist() change declaration int km; change method int getDist() { km = kilmet*mile; return km; }
21st Aug 2019, 7:11 PM
Igor Kostrikin
Igor Kostrikin - avatar
0
Thanks for your help! But I'm still curious, so why is it producing different value? I don't understand 🤔 Care to elaborate?
21st Aug 2019, 7:20 PM
khoirul Hadi
khoirul Hadi - avatar
0
Incorrect initialization of "km". "mile" at this moment has no value
21st Aug 2019, 8:51 PM
Igor Kostrikin
Igor Kostrikin - avatar
0
Oh i see, so the x haven't been assigned to the mile when the program jump to "private:" to initialize mile kilmet and km. Ok i got it. Thanks again.
22nd Aug 2019, 12:13 PM
khoirul Hadi
khoirul Hadi - avatar