anthony anthony - 6 months ago 48
C Question

in beginning C programming using methods

I'm brand new to C, and I need to ask the user to type in a runners time for a 100 meter dash, and converts the time to show how many meters traveled and how many miles and km converted from the input time, using given conversions and using methods to produce it. Here is my code so far:


double getMeters (double time){
double m = 100/time;
return m;

double getFeet (double time) {
double ft = (100/time) * 3.280839895;
return ft;

double getKm (double time){
double km = (100/time) * 1000 / 3600;
return km;

double getMiles (double time){
double mi = (100/time) * 1000/ 3600 * 1.6;
return mi;

void main() {
double time, m, mi, km, ft;
printf("\nPlease enter the winning time of the race: " );
m = getMeters(time);
printf("\n %.2f meters per second", m);
ft = getFeet(time);
printf("\n %.2f feet per second", ft);
km = getKm(time);
printf("\n %.2f kilometers per hour", km);
mi = getMiles(time);
printf("\n %.2f miles per hour", mi);
return 0;

The output should be all numbers of type double but all I get when I run it is 0.00 for each thing. Why isn't it working??!? Help would be appreciated.


to read a double, you should use %lf instead of %f.