PRO
Michael
asked

Expert
Sudip Bhandari answered
Hi Michael! That's a great question!
When converting kilometers to miles, we use the conversion factor:
1 kilometer = 0.621 miles
Since 0.621 is a decimal, there’s a high chance that both the input (kilometers) and the output (miles) could involve decimal values. That’s why it's better to use the double
data type for both variables.
In short, use double
when you feel the value can include a decimal part, on the other hand, use int
when you feel the value cannot include a decimal part (like an age).
I hope this clarifies things for you! Let me know if you have any more questions; I'm here to help.
C++
This question was asked as part of the Learn C++ Basics course.