Quote:
Originally Posted by tukriss
please give me the answer to this question
The distance between two cities in killometers is input through a keyboard.
Write a C program to convert and print this distance in;
1.Meters
2.Feets
3.Inchs
4.Centimeters
thank you.
hi there,
actually i can code to you by now but i do'nt have such enough time to spent with you , ive post some introduction then i let tou to finish it by your self ok!!!
#include <iostream.h>
#include <conio.h>
#include <math.h>
double GetInput();
double convertToMeters ( double);
double convertToFeets ( double);
double convertToInches (double);
double convertToCentimeters (double);
int main ();
{
cout << " Welcome To Unit Conversion:\n ";
cout <<" 1. Convert Unit to Meters:\n";
cout <<" 2. // put all the other stuff you needed
.......................................
cout << "4. " Exit";
{
double input;
double converted;
int choice = -1;
while (choice !=4)
{
cin>> choice;
if (choice !=4)
{
input = GetInput ();
if ( choice == 1)
converted = convertToMeters ( input);
else if ( choice == 2)
converted = convertToFeets ( input);
//........input others similar to this up to
else if (choice >=5) // for wrong input selection
cout <<" wrong input:";
cout<<" you convert:\t" << input << converted;
}
}
}
getch ();
return 0;
}
double GetInput()
{
cout <<" enter Unit:\t";
double input;
cin >> input;
return input;
}
double convertToMeters ( double input)
{
return input * ( // put the formula to convert it to meters // do not put "=" sign on it ,put semi-colon after the fomula ok!!!!)
}
double convertToFeets ( double input)
{
//similar to above but to feet
}
//do the same in the remaing two
double convertToInches (double)
double convertToCentimeters (double)
}
then compile it, note that this is case sensitive ok be sure not to miss something
regards,
mike