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

8/21/2019 6:41:42 PM

khoirul Hadi

4 Answers

New Answer


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; }


Thanks for your help! But I'm still curious, so why is it producing different value? I don't understand 🤔 Care to elaborate?


Incorrect initialization of "km". "mile" at this moment has no value


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.