Shannon C
2008-11-25 17:33:06 UTC
Total Inches = 63,360 * Miles + 36 * Yards + 12 * feet + Inches
Use the following formula to determine the equivalent meters:
Meters = Total Inches/ 39.37
Declare constants for all numeric values in the two formula above. The variable used to represent the number of meters and the numeric constant 39.37 must be declared as the data type double. the constants and data types in the first formula should be declared as integers. Convert the Total Inches in the second formula to a Double data type before using it in the calculation. Set Option Strict to on in your code. (Hint: After the number of meters has been determined, the maximum number of kilometers can be computed from Kilometers = Meters/1,000. Next, the remaining meters can be determined from: Remaining Meters = Meters - 1,000 * Kilometers. The number fo integer meters in Remaining Meters then can be determined from: Integer Meters = Convert.ToInt32(Remaining Meters). Continue with the same technique to compute the number of centimeters.)
Use the following test data to test your program: 2 miles, 5 yards, 2 feet, and 7 inches. The result should be 3 kilometers, 224 meters,, and 5.38 centimeters.
Did I something went wrong?
Here is my source code:
Option Strict On
Public Class Form1
Inherits System.Windows.Forms.Form
Const INCHESPERMILE As Integer = 63360
Const INCHESPERYARD As Integer = 36
Const INCHESPERFOOT As Integer = 12
Const CONVERTER As Double = 39.37
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnConvertEnglishtoMetric_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvertEnglishtoMetric.Click
Dim dblMiles As Double
Dim dblYards As Double
Dim dblFeet As Double
Dim dblInches As Double
Dim dblKilometers As Double
Dim dblMeters As Double
Dim dblTotalInches As Double
Dim dblRemainingMeters As Double
Dim dblTotalMeters As Double
dblMiles = Convert.ToDouble(nudMiles.Value)
dblYards = Convert.ToDouble(nudYards.Value)
dblFeet = Convert.ToDouble(nudFeet.Value)
dblInches = Convert.ToDouble(nudInches.Value)
' Main conversion Formula
dblTotalInches = INCHESPERMILE * dblMiles + INCHESPERYARD * dblYards + INCHESPERFOOT * dblFeet + dblInches
dblTotalMeters = dblTotalInches / CONVERTER
txtKilometers.Text = Convert.ToString(Convert.ToInt32(dblTotalMeters / 1000))
dblKilometers = Convert.ToInt32(dblTotalMeters / 1000)
dblRemainingMeters = (dblTotalMeters - (1000 * dblKilometers))
txtMeters.Text = Convert.ToString(Convert.ToInt32(dblRemainingMeters))
dblRemainingMeters = Convert.ToDouble(dblRemainingMeters - Convert.ToInt32(dblRemainingMeters))
txtCentimeters.Text = Convert.ToString(dblRemainingMeters * 100)
End Sub
End Class