55.7k views
2 votes
Write a C# Console application that converts a mile into its equivalent metric kilometer measurement. The program asks the user to input the value of miles to be converted and displays the original miles and the converted value . Test your code with inputs (1) 10 miles, (2) 3.25 miles.

User Marijne
by
7.4k points

1 Answer

3 votes

Answer:

Following are the program in c#

using System; // namespace system

using System.Collections.Generic; // namespace collection

using System.Linq;

using System.Text;

namespace test // namespace

{

class Program1 // class

{

static void Main(string[] args) // Main function

{

double nMiles, nKm;

Console.Write("Enter Value In Miles : ");

nMiles =Convert.ToDouble(Console.ReadLine());

nKm = (nMiles / 0.62137);

Console.WriteLine("Output:");

Console.WriteLine("Value In Miles :" + nMiles);

Console.WriteLine("Value In KM :" + nKm);

Console.Read();

}

}

}

Output:

Case A-

Enter Value In Miles : 10

Value In Miles : 10

Value In KM : 16.09347

Case B-

Enter Values In Miles : 3.25

Value In Miles : 3.25

Value In KM : 5.230378

Step-by-step explanation:

Here we take a input value in "nMiles" variable and converted into a Km. that will stored in "nkm" variable . To convert miles into km we use calculative formula Km=(miles/0.62137). This formula convert the entered value into km and finally print the value of miles and km miles variable.

User Pixelbadger
by
9.1k points