CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 25

Threaded View

  1. #16
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Sudoku solving algorithm

    Quote Originally Posted by supahamster View Post
    As I stated in the previous post: I have looked through the code several times, and I cannot spot the problem. I think it may be a logical error, but as far as I can tell, there is none. Seeing as I am not in a c++ class and do not have anyone else to refer to (I ran this by my friend and he didn't spot any errors either),
    That's the problem. Very few human beings can "spot" errors without debugging the program, unless the error is so glaringly obvious. There are too many loops, variables, paths the code can take, etc. to make it even possible for anything but an extraordinary human being to try and figure out "by sight".

    A trained programmer can look at just a few lines of code that they did not write (around 50, if that many) and tell if there is something logically wrong with it. If you're attempting to just "look" at the code and spot logical errors without stepping through the code, then you're better than most of the programmers that I know.

    Programmers used to "hand debug", where they would step through the code with pencil and paper. This worked somewhat, but it is still error prone, as again, we're mere human beings -- we get tired, lose our place in the code, forget to write down stuff, etc. That's why interactive debuggers were developed, so as to eliminate the possiblity of these things happening when debugging a program.
    will anyone give me some suggestions as to how to go about debugging this, or tell me if there is a logical error in my method of solving?
    We did. Single step through the program.

    Again, you wrote the program, therefore you should know exactly what each step, loop, assignment, etc. is supposed to do at every step of execution. You know what is supposed to go in as input, and what is supposed to come out at the other end as the result, and hopefully you wrote the code using these suppositions. Now that you wrote the code and it is not doing what you want it to do, you inspect where the program starts to break down.

    "What happens after this loop I wrote? Are the values correct? What is the value of this variable? It was supposed to be x, but it's y. It must be this loop -- yep, there is the problem". These are the questions that you should be asking yourself when debugging a program.
    Again: the program does not crash, but it never passes the last if statement of "if(correctnum==true)" even when I know there are several places on the grid where it should.
    So now you know the end result, run the debugger and see why that last if() statement is not true.

    Also, instead of telling us what to cut, paste, copy, etc. to get a working program, post the entire program that you are now using. It is less likely to have issues if we get the code from you without having to edit anything.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; May 14th, 2009 at 04:09 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured