Converting from miles to kilometers

hey guys , i started to learn programming from a book called c++ principles by the creator of the language in the exercises he wanted a program to convert from mile to kilo , i made the program run but i have wrong values i dont know why
when i put 1 in the mile i get "you have 1,96642e+009 kilometers
here is my code.

1
2
3
4
5
  int miles;
double kilometers=miles*1.609;
cout<<"Enter Your miles\n";
cin>>miles;
cout<<"you have " << kilometers << " " <<"kilometers";
closed account (2UD8vCM9)
Why are you doing
kilometers=miles*1.609;

before
cin>>miles;

How are you supposed to convert your miles into kilometers before you know how many miles to convert?
can someone help me on my thread?
@pindrought , thanks it worked now after u told me , but does it matter? does the sequence is important? i defined a variable and i want to use it later i already defined miles and kilometers then i said later cin in miles and cout the kilometers which where defined ed
@IceStorm , i am beginner , but i think alot of people will help you be patient
closed account (2UD8vCM9)
@Zamalek it does matter, because this is not like real life mathematics.

In algebra, I can say the following.
M = miles
K = Kilometers
M = K*1.609


And i'll know based off of that what M or K is correspondingly.

However, in programming it is read from the top to the bottom.

So I could do something like.

1
2
3
4
float Miles = 30;
float Kilometers = Miles*1.609; //At this point kilometers is 48.27
Miles = 50; //Kilometers didn't change. The reason kilometers didn't change is because we haven't told it to change again. It is still 48.27
Kilometers = Miles*1.609; //Now kilometers is 80.45 



See? It will only updated when we tell it to update
@Pindrought , yes i got it now thanks so much for your time man.
Last edited on
Topic archived. No new replies allowed.