- Home
- .NET coding challenges
- Write a C# function to convert MPH to KPH
Write a C# function to convert MPH to KPH
If you have an application that involves recording the speed, you may need to convert miles-per-hour (MPH) to kilometers-per-hour (KPH).
Here is your chance to write a C# static function that allows you to convert MPH to KPH.
Start off with this code:
public class SpeedHelper
{
public decimal ConvertToKph(decimal mph)
{
}
}
Inside the SpeedHelper
class, there is a ConvertToKph
function. It expects an mph
parameter which is the speed in MPH which we wish to convert to KPH.
1 mile converts to 1.6093 km. Finish the ConvertToKph
function so it returns the value in KPH.
For example, if we passed in ConvertToKph(100)
, we would expect the return value to be 160.93 (100 * 1.6093).
Give us your anonymous feedback regarding this page, or any other areas of the website.
Related challenges
Removing the last character from a string
This coding challenge involves writing a C# method that will removing the last character from a string and returning the value.
Contains online code editor
Convert hours, minutes and seconds into a time formatted string
Pass in the hours, minutes and seconds into a method and get it to return a time formatted string which should include leading zeros.
Contains online code editor