Our teacher have asked us to make a program in C language to read the difference between two cities in km, m, cm, inches and feets... I have tried every hell to make this work... I am not able to combine it all together... please help!!! I am so confused.

here is sum rough work i have done:
km-1
m-km/1000
cm-m/1000
1inch-2.54cm
1feet-12 inch

thx!!!

u first try the conversion of one form to another first.
After u have tested all of them in individual programs u can try to integrate them............

u first try the conversion of one form to another first.
After u have tested all of them in individual programs u can try to integrate them............

it doesn't work actually they have not taught us all this jus da simple stuff and now they expect us to make something we have never done before don't even have a hint but i went through a tutorial with similar kind of thing... i'll show you what i did but it just shows 0,0,0 n 0 lol! something is badly wrong with the script!!!

#include<stdio.h>
#include<conio.h>
void main();
{
int km=0;
int meter =0;
int cm=0;
int inches=0;
int feet=0;

const int km_per_meter=1000;
const int meter_per_cm=1000;
const int cm_per_inches=2.54;
const int inches_per_feet=12;

printf("Enter distance of city 1 in Km: ");
scanf("%d",&inches);

meter=km/km_per_meter;
cm=meter/meter_per_cm;
inches=cm/cm_per_inches;
feet=inches_per_feet;

print("that is equivalent to %d meter; %d cm; %d inches and %d feets\n",meter,cm,inches,feet);
}
getch();
}

Your logic is wrong. 1 KM == 1000 M == 100000 CM.

look at the following part of code that u have written.......

meter=km/km_per_meter;
cm=meter/meter_per_cm;
inches=cm/cm_per_inches;
feet=inches_per_feet;

u have never initialized the values in the RHS of the statements. e.g.

meter = km/km_per_meter;

here km = 0
km_per_meter = 1000
and (0/1000) = 0
hence when u r trying to print 'meter' u are getting a zero.

This is programming and the statements will be executed in the sequence they appear.

the mistake u did is the following

printf("Enter distance of city 1 in Km: ");
scanf("%d",&inches);

u should have written

printf("Enter distance of city 1 in Km: ");
scanf("%d",&km);

another mistake that u did is in the following line

feet=inches_per_feet;

it should have been

feet=inches/inches_per_feet;

hope that helps

Thank you so much I am done with it... Thanx a million!!!! God Bless!!!:)

how to change conversions in c language

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.