Hi everyone,
Today I spotted an error in my code and, unfortunately my IDE doesn't have any debug mode (actually it just doesn't work) so I'm referring to YOU guys to find out where is my error.
Before the code, I just wanted to tell you that I think the error comes from the while conditions loop.
cout << "Please enter your name: ";
Player player;
player.setName();
Player cpu(Randname());
cout << cpu.getName() << " just entered the table.\n" << endl;
while(!cpu.lost() || !player.lost() || !player.hasBlackjack() || !cpu.hasBlackjack() ||(!player.stands() && !cpu.stands()));//AI OR PLAYER IS ALIVE or player and cpu don't stand
{
if(!player.lost())
{
//PLAYER TURN
PlayerTurn(player);
}
if(!cpu.lost())
{
//CPU TURN
AITurn(cpu);
}
cout << "DEBUG end of turn." << endl;
}
AAaand I can never see the "DEBUG end of turn" line :(
Am I even entering the loop?
Thanks for every answer I get
If you never see the "DEBUG end of turn" you are not entering the while loop. Though we won't be able to tell you what the error is and why it is occurring without seeing all those functions you have in the while condition.
I would suggest start studying up on how a debugger works and if you don't have a working one get one. They can be the most important tool a programmer has in his toolbox so it is basically a must to know how they work and how to use them.
Here is a very good one for VS2010 that you can use. http://www.codeproject.com/Articles/79508/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
This will also teach you the concept and the knowledge can be transferred to almost any debugger.
This really just needs to be debugged. If you can't debug yourself (since you say your debugger is broken?), then perhaps can you post the full source so that we can compile/debug on our machine? If it's too big to post on the board, you can always zip it up and throw it on dropbox or something.
Why would you put braces around one and not the other? That's like wrapping a box of milk chocolate but not wrapping an identical box of dark chocolate, and giving both to your loved one...you love your compiler, don't you?
Also, have you tried outputting at the beginning of the loop to see if it even gets in the loop or not? Putting output at the end after a whole load of statements is not helpful.
Because you wrapped a box of milk chocolate, bananas and a car. While you were eating they robbed you.
All that's left is milk, nicely wrapped. You are too depressed to undress it.
By the way, it is not the compiler you should worry about.
Yeah nice catch! I'm not on my computer right now so I can't check it out, but it's probably it. This loop used to be a do{}while; that's why there is a semicolon, my bad.
Anyway thanks to all of you guys for answering me and proposing me upgrades for my code that really helped me out ;)
Compile with warnings enabled at the highest level and a reasonable compiler would catch it for you.
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
int main()
{
int i = 7 ;
// g++ with -Wextra: *** warning: suggest braces around empty body in an 'if' statement
// msvc with -W4: **** warning ';' : empty controlled statement found; is this the intent?
if( i == 7 ) ;
std::cout << "hello world\n" ;
}
> g++ does not give a warning if it were a `while' instead of an `if'
Yes. Thanks.
Perhaps because while( *dest++ = *srce++ ) ; is almost canonical.
> if there is an `else'
Then it only warns about an empty body in the else statement, which is reasonable. Because unless the if having an empty body was intented, we would have got an error: else without a previous if.