Results 1 to 4 of 4

Thread: help please

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    5

    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

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: help please

    "Would you do my homework" is not a valid question. Do you have a specific question regarding the code?

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    5

    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..

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Dim Const METRES_PER_KILOMETRE As Integer = 1000
    2. Dim totalMetres As Integer = 2759
    3. Dim wholeKilometres As Integer = totalMetres \ METRES_PER_KILOMETRE
    4. Dim remainingMetres As Integer = totalMetres Mod METRES_PER_KILOMETRE
    5.  
    6. MessageBox.Show(String.Format("{0} metres is {1} kilometres and {2} metres.", totalMetres, wholeKilometres, remainingMetres))
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width