-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathconvert_miles_to_kms.cpp
More file actions
45 lines (36 loc) · 1.37 KB
/
Copy pathconvert_miles_to_kms.cpp
File metadata and controls
45 lines (36 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*******************************************************************************
*
* Program: Convert Miles To Kilometers
*
* Description: Program to convert a distance in miles to a distance in
* kilometers using C++.
*
* YouTube Lesson: https://www.youtube.com/watch?v=4Cd8pKAfrMA
*
* Author: Kevin Browne @ https://portfoliocourses.com
*
*******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Variables to store distances in miles and kilometers. Type double is
// used because distances may have decimal places and double type variables
// can store numbers with decimal places.
double miles, kilometers;
// Prompt the user to enter the distance in miles
cout << "Miles: ";
// Store the entered distance in the variable miles
cin >> miles;
// Convert the distance in miles to the distance in kilometers and store
// the result in the variable kilometers using the formula found here:
// https://en.wikipedia.org/wiki/Kilometre
kilometers = miles / 0.621371;
// Output the text "Kilometers: "
cout << "Kilometers: ";
// Then output the value stored in the variable kilometers with 2 decimal
// digits of precision using the stream manipulators fixed and setprecision.
cout << fixed << setprecision(2) << kilometers << endl;
return 0;
}