Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this exercise, you are asked to write a program to create a table for conver

ID: 3744639 • Letter: F

Question

For this exercise, you are asked to write a program to create a table for converting from kilometres per hour to miles per hour. This is similar to Activity 2 from the tutorial exercises; however, be mindful of the details! The exercise has been changed slightly for the AMS.

Write a program that first displays the column headings of the two units of speed you are asked to convert between. The leftmost column must be justified to the left side of the screen.

Your program should then display a number of lines, showing the speed you are converting from and the speed you are converting to on each line. These should be spaced to line up with the column headings, and the left column should once again be left-justified.

For this exercise your program must start at 45kph and increase by 10kph each time, and show a total of exactly 15 lines not including the column headings.

Only show values to 2 decimal places.

As an example, if you were asked to start at 10kph and increase by 10kph each time, and show a total of five lines, your table would look like this:

KPH        MPH
10         6.21
20         12.43
30         18.64
40         24.85
50         31.07

The following formula may be helpful: 1 mph = 1.60934kph

USE CODE:

Explanation / Answer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SpeedConversion {
class MilesPerHourTable {
public static void Main() {
// Write your code to create the KPH to MPH table here
int mph = 45;
double kph;
Console.WriteLine("{0, -10} {1, -10}", "MPH", "KPH");
for(int i = 1; i <= 15; i++)
{
kph = mph / 1.60934;
//show both columns with width 10 left justified and display 2 decimal places
Console.WriteLine("{0,-10} {1,-10:0.00}", mph, kph);
mph += 10;

}
Console.WriteLine(" Hit Enter to exit.");
Console.ReadLine();
}
}
}

output

--------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote