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:
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
usingnamespace 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