In a couple of weeks I will be joining a project that (currently) uses LabView for development. To get myself at least somewhat familiar before this happens I have been creating some simple projects in the trial version of the software. Someone challenged me to write a simple program that could preform simple division without using the division operator.
I've written the program successfully, but my main while
loop seems to run one too many times. Here is my program:
The user inputs a dividend and divisor and the program will continually subtract the divisor from the dividend until the dividend becomes <= 0, at which point it should break. The program runs successfully, but when the loop finally stops the dividend always equals x below 0 (where x is whatever number the divisor is). While debugging the application I found the problem, when the loop comparison happens for the final time the dividend will equal 0 and evaluate to 'false' however the code inside the loops executes one last time before the loop breaks. This is what I would expect from a do-while loop, but not a simple while.
Just to prove to myself that it wasn't an (hopefully) obvious logic error I wrote (what I consider to be) an equivalent program in python that does exactly what I expect.
I've spent a long time googling, staring at it, I even did it on paper but I cannot figure out why it doesn't do what I expect. What gives?