Connecting Tech Pros Worldwide Forums | Help | Site Map

I cant do my home work,please help me.i am stuck

Newbie
 
Join Date: Nov 2006
Location: ghana
Posts: 2
#1: Dec 7 '06
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.

DeMan's Avatar
Lives Here
 
Join Date: Nov 2006
Location: Adelaide, SA
Posts: 1,748
#2: Dec 7 '06

re: I cant do my home work,please help me.i am stuck


Hopefully you know how to write code.....

1)there are 1000 metres in a kilometre
2) a foot is (approximately) 30 centimetres
3) an inch is (approximately 2.54 centremetres, alternatively 12 inches are [approximately] 1 foot)
4) There are 100 Centimetres in a metre.

Using the information above you can consruct a method to convert km into any of the units mentioned here.

If you want help with the actual code I suggest you submit some of your own. There are many people here more than willing to help with your assignment, but few who would do your assignment for you.
Member
 
Join Date: Nov 2006
Location: Antipolo, City
Posts: 55
#3: Dec 8 '06

re: I cant do my home work,please help me.i am stuck


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
Reply


Similar C / C++ bytes