In: Computer Science
Create an C# application named ConvertMilesToKilometers whose Main() method prompts a user for a number of miles, passes the value to a method that converts the value to kilometers, and then returns the value to the Main() method where it is displayed.
Have a look at the below code. I have put comments wherever required for better understanding.
using System;
// create main class
class MainClass {
// create method to convert miles to km...
public static double ConvertMilesToKilometers(int miles){
return miles*1.609344;
}
public static void Main (string[] args) {
// take user input for miles
Console.WriteLine ("Enter number of miles: ");
int miles = Convert.ToInt32(Console.ReadLine());
// call the ConvertMilesToKilometers function and display on console
Console.WriteLine ("Number of KM is: "+ConvertMilesToKilometers(miles));
}
}
Happy Learning!