Something strange

This is a discussion on Something strange within the C++ Programming forums, part of the General Programming Boards category; I'm making a chess game to learn a bit more about C++. When a player tries to make a move ...

  1. #1
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218

    Something strange

    I'm making a chess game to learn a bit more about C++. When a player tries to make a move it gets validated. My validation was not working tho so I had a play around with the code to try an figure out what was going wrong. Heres a snippet from a validation function:
    Code:
    bool piece::CheckMove(int sx, int sy, int ex, int ey, char t)
    {
         printf("%c", t);
         if(t=='k')      if(RookMove(sx, sy, ex, ey)==true)return true;     
         else if(t=='t') printf("hdeghsdav");//if(KnightMove(sx, sy, ex, ey)==true)return true;   
         else if(t=='s') if(BishopMove(sx, sy, ex, ey)==true)return true;   
         else if(t==6)   if(QueenMove(sx, sy, ex, ey)==true)return true;   
         else if(t==5)   if(KingMove(sx, sy, ex, ey)==true)return true;   
         else if(t=='n') if(PawnMove(sx, sy, ex, ey)==true)return true;        
    }
    What I don't get here is that the first printf statment prints the character 't' when I move a knight, but the stuff in the second printf statment does not get displayed even though the variable t=='t'. Anyone know why this would be?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    When you're new, bite the bullet and use proper indenting and full bracing.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    >_< Yeah, I got it. There was another 'if' statement after the first 'if' and the 'else if' was following the second if statement.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange error -- COM DLL is not installed correctly?
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 07-16-2007, 08:32 AM
  2. strange linking error -- can not find shared library
    By George2 in forum C Programming
    Replies: 2
    Last Post: 07-10-2006, 10:51 PM
  3. Strange results using dnsapi and windns
    By Niara in forum Networking/Device Communication
    Replies: 3
    Last Post: 08-13-2005, 10:21 AM
  4. Strange response from MSVC
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 04-17-2004, 07:40 AM
  5. bcc32 compiling error (really strange!!)
    By jester in forum C++ Programming
    Replies: 14
    Last Post: 01-26-2002, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21