Miles to KM. Km to Miles etc..

#include <stdio.h>

double m2km(double); //Convert Miles to KM
double km2m(double); //Convert KM to Miles

int main(){

int loop = 1;

int choice;

double miles;

double km;

while(loop == true){

printf("Please choose a conversion:\n"

"1: Convert miles to kilometers\n"
"2: Convert kilometers to miles\n"

"3: Exit Program\n"

"> ");

scanf("%i", &choice);

switch(choice){

case 1:

printf("Enter the number of miles to convert to kilometers:\n"

"> ");

scanf("%d", &miles);

printf("%.2d miles = %.2d kilometers\n", miles, m2km(miles));

break;

case 2:

printf("Enter the number of kilometers to convert to miles:\n"

"> ");

scanf("%d", &km);
printf("%.2d miles = %.2d kilometers\n", km, km2m(km));

break;

case 3:

loop = 0;

break;
default:

printf("Invalid Entry, please try again.");

break;

}
}
return 0;

}
//Other Functions:

double m2km(double x){

return x*1.609344;

}

double km2m(double x){

return x*0.621371192;
}
Topic archived. No new replies allowed.