Computer Science Canada Making a distance converter |
Author: | Andr3iB [ Sat Sep 15, 2007 1:38 am ] |
Post subject: | Making a distance converter |
Hi to all, I need help with making this converter (I'm fairly new to turing). We have to convert from miles, to yards to feet ..... This is what I have so far
var combo : real var ans, ans2 : string put "What do you want to convert from? (miles, yards, feet, inches, kilometers, meters or centimeter)" get ans put "Into what? (miles, yards, feet, inches, kilometers, meters or centimeter)" get ans2 put "" put "Please enter the number of ", ans, " you want to convert into ", ans2, "!" get .... I don't know what to get (the last line), because I don't know ans or ans2.. so how can I calculate then? Any help is greatly appreciated. THNX |
Author: | Tony [ Sat Sep 15, 2007 2:21 am ] |
Post subject: | RE:Making a distance converter |
But you do know what ans and ans2 are. They are the user answers fetched earlier in the program! Instead of get mile or get feet, you should be doing a more general get distance_value it will still be the same 1 or 2 or 42.5. You will know the type of the measurement from the response in ans. |
Author: | Andr3iB [ Sat Sep 15, 2007 10:22 am ] |
Post subject: | Re: Making a distance converter |
Thanks Tony for the help, but I still don't know how to manipulate distance_value for the conversion. For Example ---- i want to convert from miles to feet (1mile=5280feet) so ans = miles ans2 = feet distance_value = 2 (i want to convert 2 miles to feet) How do i manipulate distance_value to give me 10560 feet - not knowing that the user typed in miles (because, as you said, i do know ans, but how do i use and and distance_value to give me the proper ans2). Do I just have to make a whole list of if statements? Sorry if my question is confusing.. I too am a bit confused ![]() |
Author: | Nick [ Sat Sep 15, 2007 10:44 am ] | ||
Post subject: | RE:Making a distance converter | ||
yea just use if statements such as
there might be an easier way but i cant think of one atm |
Author: | Andr3iB [ Sat Sep 15, 2007 10:47 am ] |
Post subject: | Re: Making a distance converter |
Well thnx a whole lot for all the help, really appreciate it. I guess I will use if statements after all. Thnx ![]() |
Author: | Tony [ Sat Sep 15, 2007 2:08 pm ] |
Post subject: | RE:Making a distance converter |
Well you have 7 different distance units mile, yard, feet, inch, meter, km, cm That makes for 42 different conversions. If writing out 42 if statements seems kind of excessive - it is. So there must be an easier way. There is ![]() Always convert to a common unit first. Lets say cm. So if we are converting from miles to feet. We first have 7 if-elseif statements to convert from miles to cm. We then have 7 similarly structures if-elseif statements to convert from cm to feet. That's 14 statements total, down from 42. Not bad. |
Author: | Andr3iB [ Sat Sep 15, 2007 3:12 pm ] |
Post subject: | Re: Making a distance converter |
Thanks a lot Tony, that's really helpful to know. Thanks to all for all the help. Really appreciate it. |