﻿ C++ Exercises: Converts kilometers per hour to miles per hour - w3resource

# C++ Exercises: Converts kilometers per hour to miles per hour

## C++ Basic: Exercise-51 with Solution

Write a C++ program that converts kilometers per hour to miles per hour.

Visual Presentation:

Sample Solution:

C++ Code :

``````#include<iostream> // Including input-output stream header file

using namespace std; // Using the standard namespace

int main() // Start of the main function
{
float kmph, miph; // Declaring floating-point variables for kilometers per hour and miles per hour

cout << "\n\n Convert kilometers per hour to miles per hour :\n"; // Displaying the purpose of the program
cout << "----------------------------------------------------\n";

cout << " Input the distance in kilometer : "; // Prompting the user to input distance in kilometers
cin >> kmph; // Taking input of distance in kilometers from the user

miph = (kmph * 0.6213712); // Converting kilometers per hour to miles per hour using the conversion factor
// Displaying the converted values
cout << " The " << kmph << " Km./hr. means " << miph << " Miles/hr." << endl;

cout << endl; // Displaying an empty line for better readability

return 0; // Returning 0 to indicate successful program execution
}
``````

Sample Output:

``` Convert kilometers per hour to miles per hour :
----------------------------------------------------
Input the distance in kilometer : 5
The 5 Km./hr. means 3.10686 Miles/hr.
```

Flowchart:

C++ Code Editor:

What is the difficulty level of this exercise?

﻿