222k views
1 vote
Write a C++ program that will convert distance measurements from miles to kilometers. Specifically, the program needs to convert 0, 10, 20, 30, 40 , 50, 60, 70, 80, and 90 miles to kilograms displaying both the number of miles and the number of kilograms on the same line.

User Runeh
by
4.8k points

1 Answer

5 votes

Answer:

// here is code in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// loop that will convert 0,10,20.....90 miles to kilometer

for(int a=0;a<=90;a=a+10)

{

// convert miles to kilometer

double kilo_m=a*1.609;

// print the result

cout<<a<<" miles is equal to "<<kilo_m<<" kilometer."<<endl;

}

return 0;

}

Step-by-step explanation:

Run a for loop from 0 to 90.First change 0 miles to kilograms by multiply 1.609. Then Increment "a" by 10 until it "a" is less or equal to 90.And change them into kilometer.

Output:

0 miles is equal to 0 kilometer.

10 miles is equal to 16.09 kilometer.

20 miles is equal to 32.18 kilometer.

30 miles is equal to 48.27 kilometer.

40 miles is equal to 64.36 kilometer.

50 miles is equal to 80.45 kilometer.

60 miles is equal to 96.54 kilometer.

70 miles is equal to 112.63 kilometer.

80 miles is equal to 128.72 kilometer.

90 miles is equal to 144.81 kilometer.

User Michael Lewis
by
5.7k points