|
-
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
-
Sep 11th, 2008, 09:32 PM
#2
Re: help please
"Would you do my homework" is not a valid question. Do you have a specific question regarding the code?
-
Sep 11th, 2008, 09:42 PM
#3
Thread Starter
New Member
Re: help please
yes, i dont understand how to use mod....
i can get the program to run , just i dont know how to make it so that it takes kilometers
then meters out of the remainder
then centimeters out of the remainder..
-
Sep 11th, 2008, 09:57 PM
#4
Re: help please
Let's say that you have 2759 metres. You use the integer division and modulo operator to get the number of whole kilometres and remaining metres from that value:
vb.net Code:
Dim Const METRES_PER_KILOMETRE As Integer = 1000 Dim totalMetres As Integer = 2759 Dim wholeKilometres As Integer = totalMetres \ METRES_PER_KILOMETRE Dim remainingMetres As Integer = totalMetres Mod METRES_PER_KILOMETRE MessageBox.Show(String.Format("{0} metres is {1} kilometres and {2} metres.", totalMetres, wholeKilometres, remainingMetres))
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
|