Convert Kilometers To Miles In C++

What we are going to see through this article is we will see in detail Convert Kilometers To Miles In C++. We make a Simple Program About Miles to Kilometers (mi to km) conversion calculator for Length conversions with additional tables and formulas.

Input: 10 kilometers

Output:  6.21 miles

The program will use a unit formula to convert distance unit kilometers to miles.

For example, 10 kilometers = —– miles?

Since, 1 km =   0.621 miles

hence, 10 km = 10*0.621 = 6.21 miles.

Convert Kilometers To Miles In C++

Convert Kilometers to Miles in C++

#include <iostream>
using namespace std;

float KilometersToMilesConversion(float kilometers) {

      // 1 kilometer = 0.621

      float miles = kilometers * 0.621;

      return miles;

}

//Test program
int main()
{
      float kilometers;
      cout << "Enter the distance in kilometers:";

      cin >> kilometers;

      //Call conversion function

      float miles = KilometersToMilesConversion(kilometers);

      cout << kilometers << " is equal to "<< miles << " Miles";

      return 0;
}

Read Also: Students Mark Lists Program In C++

Output

The input is given as 10 by the user which means the program has to convert 10 km to —-miles.

Enter the distance in kilometers:10
10 is equal to 6.21 Miles

Final Words

What we learned through this article is to Convert Kilometers To Miles In C++. Also if you have any doubts please leave a comment via the comment box. And we ask that you benefit everyone who shared this article with your friends.

Leave a Comment