![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2006
Posts: 19
Rep Power: 0
![]() |
Hi, I'm trying to make a program to convert us to metric, where miles go to kilometers, yards to meters, and feet to centimeters. I just can't understand the y to m, and f to cm, since i need to do it in a specific way for my class. Here's the code w/ explanations at end.
Dim Miles, Yards, Feet, Inches, totalInches, totalMeters As Double
Dim km, m, cm As Double
'assign values from txt boxes
Miles = txtMiles.Text
Yards = txtYards.Text
Feet = txtFeet.Text
Inches = txtInches.Text
'convert to inches
totalInches = (63360 * Miles) + (36 * Yards) + (12 * Feet) + Inches
Miles = 63360 * Miles
Yards = 36 * Yards
Feet = 12 * Feet
'convert to meters
totalMeters = totalInches / 39.37
Miles = Miles / 39.37
Yards = Yards / 39.37
Feet = Feet / 39.37
km = Miles
m = Yards
cm = Feet
km = Int(Miles / 1000)
m = Int((totalMeters - Miles) / 1000)
cm = Math.Round(totalMeters - (km + m), 1)
'display
cm = Math.Round(cm, 2)
With lstOutput.Items
.Add("The metric length is")
.Add(km & " kilometers")
.Add(m & " meters")
.Add(cm & " centimeters")
.Add(totalInches)
.Add(totalMeters)
End WithI was trying to convert, w/ these formulas, and tested it w/ these input numbers: formula1, totalInches = 63360 * miles + 36 * yards + 12 * feet + inches #2 totalMeters = totalInches / 39.37 Note: I have no idea why i need the total inches or meters. kilometers = Int(meters/1000), i use miles instead of meters and it works. input #'s Miles = 5 Yards = 20 to 8 only this one works for me Feet = 2 to 65 Inches = 4 to 73.5 please help, thanks, i just need even at least tips on what to do, even just explanations, thanks. Last edited by dwizzle13; Oct 4th, 2006 at 8:18 PM. Reason: had too much code/ need code tags |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
As a new member, you should read the forum's Rules/FAQ, specifically, in this case, in regard to code tags. Anything less is rude to those from whom you seek help.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2006
Posts: 19
Rep Power: 0
![]() |
sorry, didn't notice tht, thanks. BTW, the error was that i got riddiculios numbers on the meters and centimeters when i displayed them.
Last edited by dwizzle13; Oct 4th, 2006 at 7:56 PM. Reason: more info |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Your code is illogical and your naming conventions are confusing. Miles is not equal to 63360 * Miles. That gives you inchesPerMile. Still, a name is just a name if you don't get confused. The problem is that you are multiplying Miles by 63360 at the beginning of your code, and again in line 4. That gives you 63360*63360*Miles, which is a somewhat larger number than you want. Similarly, elsewhere.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Oct 2006
Posts: 19
Rep Power: 0
![]() |
i fixed the miles, but the miles = 63360 * Miles the first time is because i had to change 5 miles into its inch equivilent, and the same w/ the others, but i don't know why, it was just the way the problem goes. So what else is wrong? I'll update the above code.
|
|
|
|
|
|
#6 |
|
Expert Programmer
|
I don't really get what your doing with your code. It should be simple. Perhaps your over thinking it.
Feet = CM * 30.48 Metres = Yards * 0.9144 How hard is that to throw into the equation? I'm not amzing at math, and never realyl had to bother with conversions, but if you get your math right, consider posting all of your code. Also, as you said, you have to do it a paticular way for your class, so it may not be as easy as just that. The class is to teach you programming, not math. If you have problems with the math, simply google the equations. the google calculator always helps me. I have noticed that you haven't declared any of the variables. Some might tell you that vb is sloppy and will do it for you. In some cases that is true, but I have experiences that say otherwise. |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Oct 2006
Posts: 19
Rep Power: 0
![]() |
ok, i don't think it'll work, i'm trying to convert us to metric. I'll post the full code above.
|
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You can't multiply them twice. The yards and feet things have the same problem. You are going to have to choose one or the other. You can say,
Miles = 63360 * Miles Yards = 36 * Yards Feet = 12 * Feet totalInches = Miles + Yards + Feet totalInches = (Miles * 63360) + (Yards * 36) + (Feet * 12)
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#9 |
|
Newbie
Join Date: Oct 2006
Posts: 19
Rep Power: 0
![]() |
Ok, here's the fresh code, my only problem is the answers(output) of meters and cm are 0 meters, and 8057.6 cm. I needed to get an answer of 65 meters and 73.5 centimeters.
Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
Dim Miles, Yards, Feet, Inches, totalInches, totalMeters As Double
Dim km, m, cm As Double
'assign values from txt boxes
Miles = txtMiles.Text
Yards = txtYards.Text
Feet = txtFeet.Text
Inches = txtInches.Text
'convert to inches
Miles = 63360 * Miles
Yards = 36 * Yards
Feet = 12 * Feet
totalInches = Miles + Yards + Feet
'convert to meters
totalMeters = totalInches / 39.37
Miles = Miles / 39.37
Yards = Yards / 39.37
Feet = Feet / 39.37
km = Miles
m = Yards
cm = Feet
km = Int(Miles / 1000)
m = Int((totalMeters - Miles) / 1000)
cm = Math.Round(totalMeters - (km + m), 1)
'display
cm = Math.Round(cm, 2)
With lstOutput.Items
.Add("The metric length is")
.Add(km & " kilometers")
.Add(m & " meters")
.Add(cm & " centimeters")
.Add(totalInches)
.Add(totalMeters)
End With
End Sub |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Oct 2006
Posts: 19
Rep Power: 0
![]() |
srry about missing tags, etc... it's hard to do this prog, and i need help since i have no idea about it, especially this part:
km = Int(Miles / 1000)
m = Int((totalMeters - Miles) / 100)
cm = Math.Round(totalMeters - (km + m), 1) |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Visual Basic 2005 Express Edition For Dummies | ReubenK | Book Reviews | 3 | Jul 31st, 2007 8:47 AM |
| Compiling Maverik 6.2 (from C) | megamind5005 | C | 16 | May 3rd, 2006 5:41 PM |
| visual basic pixel image comparison | youngnoviceinneedofhelp | Visual Basic | 3 | Mar 19th, 2006 1:57 PM |
| Enquiry About Visual Basic Project | kbkhoo5053 | Visual Basic | 13 | Feb 15th, 2005 2:20 AM |