![]() |
Visual Basic Converter Problem
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 DoubleI 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. |
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.
|
sorry, didn't notice tht, thanks. BTW, the error was that i got riddiculios numbers on the meters and centimeters when i displayed them.
|
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.
|
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.
|
I don't really get what your doing with your code. It should be simple. Perhaps your over thinking it.
:
Feet = CM * 30.48How 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. |
ok, i don't think it'll work, i'm trying to convert us to metric. I'll post the full code above.
|
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:
totalInches = (Miles * 63360) + (Yards * 36) + (Feet * 12) |
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 |
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) |
| All times are GMT -5. The time now is 11:24 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC