Program7

Write your question here.
Hello!

I moved to next task, to write a program that converts miles into kilometers. Note that there are 1.609 kilometers in a mile. Here is something I put together:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;


int main()

{
   

   int a=mile;                   // Declares that mile is a type of int variable a
   cout<<"Enter the number of miles you want to convert to kilometers:\n";
   cin>>a;                        // Reads the number of miles
                     
   

  if (a>0) { cout<<" "<< a <<" miles is "<< a <<" * 1.609 kilometers\n";
    }

}



However I get error message when trying to compile...
line 13 should be either int a; or better yet int mile; I would also suggest a default value such as 0 int mile = 0; that way you won't run into uninitlization problems. Also for outputting it would be a * 1.609 << " kilometers" instead of a << " * 1.609 kilometers" this would mean if you have a == 1 you get: 1 miles is 1.609 kilometers instead of 1 miles is 1 * 1.609 kilometers
Topic archived. No new replies allowed.