|
-
Sep 11th, 2008, 09:27 PM
#1
Thread Starter
New Member
help please
it is the probem on page 130 at this link
click me
Write a program to convert a U.S. Customary System length in miles, yards, feet and inches to a
Metric System length in kilometers, meters, and centimeters. After the number of miles, yards, feet,
and inches are read from text boxes, the length should be converted entirely to inches and then
divided by 39.37 to obtain the value in meters. The Int function should be used to break the total
number of meters into a whole number of kilometers and meters. To convert textbox entries to a
numeric value, use the CDbl method rather than the Val method. Use 5 miles, 20 yards, 2 feet, and
4 inches for a sample run. It should yield a result of 8 kilometers, 65 meters, and 73.5 centimeters.
Remember to use meaningful names for all objects and comment your code. Some of the needed
formulas are as follows:
Total inches = 63360 * miles + 36 * yards + 12 * feet + inches
Total meters = total inches / 39.37
Kilometers=Int(meters / 1000)
i know this is easy code, but i just started vb last week, so ne help is needed....
heres my code so far......
-------------------------------------
Public Class Form1
Private Sub btnconvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnconvert.Click
Dim miles As Double
Dim yards As Double
Dim feet As Double
Dim inches As Double
miles = txtmiles.Text
yards = txtyards.Text
feet = txtfeet.Text
inches = txtinches.Text
Dim totalInches As Double
Dim totalmeters As Double
Dim totalkilometers As Double
Dim totalCentimeters As Double
totalInches = 63360 * miles + 36 * yards + 12 * feet + inches
totalmeters = totalInches / 39.37
totalkilometers = Int(totalmeters / 1000)
lstresult.Items.Add("the metric length is")
lstresult.Items.Add(totalkilometers & " kilometers")
lstresult.Items.Add(totalmeters & " meters")
lstresult.Items.Add(totalCentimeters & " centimeters.")
lstresult.Items.Add(totalInches)
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|