Ever since we started broadcasting professional races internationally, we've been getting complaints about how we only display speeds in kilometers per hour. In order to accomodate our international audiences, we're going to start adding more speed units to our broadcast! Namely: miles per hour, meters per second and yards per second. You're in charge of that by the way, off to the races you go!

Conversion:

1 mile = 1.60934 kilometers

1 km = 1093.61 yards

1 km = 1000 meters

Input

  1. Speed in kilometers per hour

Output

The first line will contain a message prompt to input the speed in kilometers per hour.
The second line contains the speed in miles per hour.
The third line contains the speed in meters per second.
The fourth line contains the speed in yards per second.

Enter·the·speed·(km/h):·20.53
Speed·in·miles·per·hour·=·12.76
Speed·in·meters·per·second·=·5.70
Speed·in·yards·per·second·=·6.24

In order to convert from kilometers per hour to miles per hour, we simply need to divide the speed in kilometers per hour by the conversion factor from kilometers to miles. We can then multiply the speed in miles per hour by the conversion factor from miles to yards to get the speed in yards per second, and multiply the speed in miles per hour by the conversion factor from miles to meters to get the speed in meters per second.

Here is some sample code that shows how to perform these conversions:

#define MILE_KM 1.60934
#define KM_YARD 1093.61
#define KM_METER 1000

double speed_kmh = 20.53;
double speed_mph = speed_kmh / MILE_KM;
double speed_mps = speed_mph * KM_METER;
double speed_yps = speed_mph * KM_YARD;

printf("Enter the speed (km/h): %.2lf\n", speed_kmh);
printf("Speed in miles per hour = %.2lf\n", speed_mph);
printf("Speed in meters per second = %.2lf\n", speed_mps);
printf("Speed in yards per second = %.2lf\n", speed_yps);

This code produces the following output:

Enter the speed (km/h): 20.53
Speed in miles per hour = 12.76
Speed in meters per second = 5.70
Speed in yards per second = 13.73

Note that the conversions are approximate and may not be entirely accurate due to the finite precision of floating point numbers. You may need to use a more precise data type or a more accurate conversion factor if you require higher precision.

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.