Thread: what syntax error ?!

  1. #1
    Slow Learner Prophet-ex's Avatar
    Join Date
    Jan 2005
    Posts
    9

    Angry what syntax error ?!

    Hello.
    This question is not specifically about game programming but the problem code is in a game I'm making so I wasn't sure where to put this thread.

    Anyways here's the snippet of code for the win/lose conditions :
    Code:
    //-------------------- WIN / LOSE ------------------------------------------\\
      if (player.hp=<0||0&&enemy.hp=>0) {cout<<"\n\n\nYOU LOST";}
      else if (enemy.hp=<0||0&&player.hp=>0) {cout<<"\n\nYOU WIN !!!\n\nCONGRATULATIONS !!!";}
      else if (player.hp&&enemy.hp=<0||0){cout<<"\n\nIT IS A DRAW";}
    On this line :
    Code:
    else if (enemy.hp=<0||0&&player.hp=>0) {cout<<"\n\nYOU WIN !!!\n\nCONGRATULATIONS !!!";}
    It says there's a syntax error before else. Could someone please tell me why 'cos I can't see what I'm doing wrong. If it matters I'm using Dev 4.9.9.0 on Windows 98. Thanks

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    =< => are backwards. >= greater than or equal to and <= is less than or equal to.

    edit: also, <= 0 || 0 doesn't make any sense. "Less than or equal to zero or equal to 0"?

  3. #3
    Slow Learner Prophet-ex's Avatar
    Join Date
    Jan 2005
    Posts
    9
    Thanks but the error is still there .....

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    >>It says there's a syntax error before else
    The error is on this line
    Code:
    if (player.hp <= 0 || player.hp == 0 && enemy.hp >= 0 ) {cout<<"\n\n\nYOU LOST";}
    If that is what you meant to have you can take out the || player.hp == 0 because it is already checked in the first expression

    Code:
    if (player.hp <= 0  && enemy.hp >= 0 ) {cout<<"\n\n\nYOU LOST";}

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    The correct way to check if something is less than or equal to is:
    Code:
     <=
    Notice that the equal sign goes after the less than symbol.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM