You are on page 1of 10

Converting Miles to Kilometers

 Your summer surveying job requires you to


study some maps that give distances in
kilometers and some that use miles. You and
your coworkers prefer to deal in metric
measurements .

 Write a program that performs the necessary


conversion,
 Convert from kilometers to miles? Or
miles to kilometers?
 What is the relationship between miles
and kilometers?
 Data requirements:
◦ Problem input
 miles // the distance in miles

◦ Problem output
 kms // the distance in kilometers

◦ Relevant formula
 1 mile = 1.609 kilometers
 Algorithm
1. Get the distance in miles
2. Convert the distance to kilometers
3. Display the distance in kilometers

Algorithm with refinement:


1. Get the distance in miles
2. Convert the distance to kilometers
1. Distance in km is 1.609 times distance in miles
3. Display the distance in kilometers
 Write the algorithm as a program
 C program
 Verify the program using sample test values.
 Example:
◦ 10 miles = 16.09 kilometers
Edit and
save program
errors

errors
Compile program

Execute program and


evaluate results
 Type the source code

You might also like