A space shuttle measured the distance between earth and Mars as a very large integer number of centimeters. Write a C++ program that reads such distance as centimeters and displays the kilometers, meters and centimeters equivalent.

Recommended Answers

All 3 Replies

please answer

What do you have so far. We will not do your work for you. Converting centimeters to meters and kilometers is a pretty simple process. I will give you a hint though. Since you are going to be dealing with very large numbers you should do this with strings instead of number types.

you could have googled and produced... 1km = 1000m, 1m = 100cm, 1km = 100,000cm. So then...

int iCentimeters = /*Whatever space shuttle records in cm*/;
int iMeters = int(iCentimeters / 100);
int iKilometers = int(iMeters / 1000);

The int() will cast away the floating point result. Now just output it to screen. Use float for a more accurate result. Have a go...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.