Select Case speed
Case 0 to 10
(code that executes if speed is between 0-10)
Case 11 to 59
(code that executes if speed is between 11-59)
(code that executes if speed is exactly 60)
(code that executes if speed is exactly 80)
(code that executes if speed is anything else)
Now suppose that you are responsible for converting the code to C. The speed variable is now a float. In addition, your boss tells you that, in addition to the values above in the VB code, you must check for a speed of 98.6 and do some extra code if the speed is that value.
First, discuss how you would go about converting this code, explaining why you're making the choices you think you need to make.
Second, what does the C code look like?
I have a problem converting this to C, since we have one case that checks for values between 0 and 10 and another case that checks for values from 11 to 59. So what happens when a value is 10.5? It is skipped completely.
Should the code would look something like this:
if (speed < 10)
else if (speed > 10 && speed < 60)
and get a hold of BCX. Kevin Diggins migrated from VB to C/C++ a few years ago and wrote BCX, a basic to C translator that has been updated and improved ever since. Some members of the BCX group have actually written a VB to BCX translator. The whole thing is absolutely free, comes with a great help file, and has all source code with it! Check it out! The BCX folks maintain a very active group at: http://groups.yahoo.com/group/bcx/