But still it returns true. |
It probably doesn't. I think you are misdiagnosing the problem. It's far more likely you are misusing the value this function returns.
But as dandy is suggesting, you need to find out what the program is actually doing, rather than guessing. Adding cout statements everywhere is one way to do this, but I find that an easier way is to just use the debugger. Now is a perfect opportunity to learn how to use it.
Here's a crash course on the basics:
There are two key features you want to use: "Breakpoints" and "Watch"
-) Set a breakpoint on code you're interested in (default key to set/remove a bp on the current line of code is F9 in MSVS). Here, you are interested in the checkWin function, so I would set a breakpoint at the start of that function.
-) Run the program and get the bug to trigger. When the program executes checkWin (or whatever line of code you put your breakpoint on), the debugger will "snap", bringing your IDE to the front and effectively "freezing" your program.
-) Open up a "Watch" window (in VS, go in the "Debug" menu -> Windows -> Watch). The watch window lets you type in the name of a variable and see its current contents. You can even modify variable contents in realtime if you want to do some tweaking.
-) Walk through your code and make sure variables are what you expect, and the program is running code you expect. You can use the below options for walking through code:
---) "Step Over" (default key=F10 in VS). Unfreezes your program and runs it for one line of code, then freezes it again. If that line of code is a function call, it will skip over the body of the function.
example:
1 2
|
int var = func(); // <- if we are frozen here, and we StepOver
var += 3; // <- the debugger will freeze here
| |
---) "Step Into" (default key=F11 in VS). Same as Step Over, but if the line calls a function, it will go into it:
1 2
|
int var = func(); // <- if we are frozen here, and we StepInto
// ... the debugger will freeze on the first line of the 'func' function
| |
---) "Step Out" (default key=Shift+F11 in VS). Runs until the current function exits, then freezes again.
-) once you're done debugging you can run (default key=F5 in VS) to "unfreeze" your program.
So yeah... do that. Step through the code, find out what it's actually doing, and see where your program is going wrong.
You can also use breakpoints to quickly see if code is actually executing. IE: if you put a breakpoint on that
return 1
line, you'll quickly know if that function actually is returning 1 or not (if the breakpoint never trips, you know it isn't)