C++ program to input miles from the user and convert miles into kilometers. The conversion factor is 1.609 kilometers per mile.

 C++

#include <iostream>

using namespace std;

int main() {
  // Declare variables
  float miles, kilometers;

  // Get the miles from the user
  cout << "Enter the number of miles: ";
  cin >> miles;

  // Convert miles to kilometers
  kilometers = miles * 1.609;

  // Print the kilometers
  cout << miles << " miles is equal to " << kilometers << " kilometers" << endl;

  return 0;
}

To run this program, you can save it as a .cpp file and compile it using a C++ compiler. For example, on Linux or macOS, you can use the following command to compile the program:

g++ -o program program.cpp

Once the program is compiled, you can run it by typing the following command:

./program

For example, if you enter 10 as the number of miles, the program will print the following output:

Enter the number of miles: 10
10 miles is equal to 16.09 kilometers

I hope this helps! Let me know if you have any other questions.

Copyright © 2025 AWS Tutorials | Distributed by Blogger Templates | Designed by OddThemes