0d: 00h: 00m: 00s

🎁 Get 3 extra months of learning — completely FREE

That's 90 extra days to master new skills, build more projects, and land your dream job.

Become a PRO
Background Image

🎁 Get 3 extra months of learning completely FREE

Become a PRO
Michael Mkhabela
last year
Michaelcountry asked

Let's say 1 kilometer is equivalent to 0.621 miles—does that mean we should use int for kilometers and double for miles?

Sudip Bhandari
Expert
last year

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.