If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Please do not worry about the different values inside CheckIntersection function..It arises due change in counting from 1 to 0. I am not sure if what I have written at the end of the c++ function is correct.

Re: Please find the bug in the c++ code

You don't seem to understand what's meant by debugging. Using the debugger you can run your program, interrupt execution at any point using breakpoints, examine the values of any variables, follow the execution line by line, use the call stack to find out how you got where you are in the code, change values, set the next line of execution and all kinds of fun stuff. Nobody's talking about using ifdefs. You need to learn how to use the debugger that comes with whatever compiler you're using.

Re: Please find the bug in the c++ code

The correct solution still eludes me. Every thing seems to work correct . I tried debugging line by line too. The method tries to search the correct combination by backtracking method. So even after fitting say 5 pieces , if it is not possible to find the correct piece , it backtracks. But, it backtacks fully and stops searching for new pieces that fit exactly.

Re: Please find the bug in the c++ code

if it is not possible to find the correct piece , it backtracks. But, it backtacks fully and stops searching for new pieces that fit exactly.

So why does it backtrack fully? Why does it stop searching for pieces that fit exactly?

The answer is not "I don't know" -- it should be "I will debug to see where the fault is in the logic".

Lastly, why not start out with a simpler test? Why do you need to jump in and try all of these pieces? How about just 4 pieces, or 3 pieces? Then you can follow the code (using the debugger) much easily with a simpler example. Then when you get the simpler version working, you then apply that to more pieces.

Re: Please find the bug in the c++ code

I suspect that part of the problem is due to array bounds issue. eg in printsolution() the loop is <= 8 when it should be < 8. This could be repeated through the code. Has all of the code been converted from Basic or just the function checkpos()? If all has been converted, I suggest you start again from the original code, size the arrays way too big for what you want and assume the index starts at 1. Get this code to work then deal with moving the index to start at 0 rather than start at 1. Also I would suggest using a meaninful const int for the array dimensions and 'magic numbers' in the code rather than have numbers like 8, 3, 1 etc scattered about the code. Also check the use of <= and confirm this is what is meant and not just <.

All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!