Question

In: Computer Science

Create an C# application named ConvertMilesToKilometers whose Main() method prompts a user for a number of...

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.

Solutions

Expert Solution

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!


Related Solutions

C# Create a console application that prompts the user to enter a regular expression, and then...
C# Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a regular expression...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression,...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a...
c# In Chapter 2, you created an interactive application named MarshallsRevenue. The program prompts a user...
c# In Chapter 2, you created an interactive application named MarshallsRevenue. The program prompts a user for the number of interior and exterior murals scheduled to be painted during the next month by Marshall’s Murals. Next, the programs compute the expected revenue for each type of mural when interior murals cost $500 each and exterior murals cost $750 each. The application also displays the total expected revenue and a statement that indicates whether more interior murals are scheduled than exterior...
Create a C# program named SalesLetter whose Main() method uses several WriteLine() calls to display a...
Create a C# program named SalesLetter whose Main() method uses several WriteLine() calls to display a sales letter to prospective clients for a business of your choice. Display your contact information at least three times in the letter. The contact information should contain at least three lines with data such as land line phone number and/or cellphone number, email address, and web address.. Each time you want to display the contact information, call a method namedDisplayContactInfo().
Conversion of numeral to roman number: Create a FLOWCHART and C++ PROGRAM that prompts the user...
Conversion of numeral to roman number: Create a FLOWCHART and C++ PROGRAM that prompts the user to enter a number (from 1-3000 only) then output the number and its corresponding roman numeral number. ***validate the input (it must be 1-3000 only) SAMPLE OUTPUT: Enter a Number: 0 Number should be from 1-3000 only (Terminated) Enter a Number: -5 Number should be from 1-3000 only (Terminated) Enter a Number: 3500 Number should be from 1-3000 only (Terminated) Enter a Number: 1994...
Write an application named MultiplicationTable that prompts the user for an integer value, for example 7....
Write an application named MultiplicationTable that prompts the user for an integer value, for example 7. Then display the product of every integer from 1 through 10 when multiplied by the entered value. For example, the first three lines of the table might read 1×7=7 , 2×7=14 , and 3×7=21 using a Loop other than While if
Create a CubesSum application that prompts the user for a non-negative integer and then displays the...
Create a CubesSum application that prompts the user for a non-negative integer and then displays the sum of the cubes of the digits.   b) Modify the application to determine what integers of two, three, and four digits are equal to the sum of the cubes of their digits.(Java Programming )
Create an ElapsedTimeCalculator application that prompts the user for a starting hour, whether it is am...
Create an ElapsedTimeCalculator application that prompts the user for a starting hour, whether it is am or pm, and the number of elapsed hours. The application then displays the time after that many hours have passed. (Java)
Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user...
Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user to enter a short sentence which ends in a period. Use Java String class methods to determine the following about the sentence and display in the console: • How many total characters are in the sentence? • What is the first word of the sentence? Assume the words are separated by a space. • How many characters are in the first word of the...
Write a program in C that prompts the user for a number of seconds and then...
Write a program in C that prompts the user for a number of seconds and then converts it to h:m:s format. Example: 5000 seconds should display as 1:23:20 (1 hour, 23 minutes, 20 seconds.) Test with several values between about 100 seconds and 10,000 seconds. use unint and remainders for this and keep it as simple as possible.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT