Thread: im stuck, cant fix..HELP

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688

    im stuck, cant fix..HELP

    I have written a small game program text program using
    if and else commands.

    when i compiled it i got this message:

    " C++ forbids comparison between pointer and integer"

    below is the error line of my code:

    if (attack =="y") {

    its really got me as the rest of my program is fine.
    does anyone know what the error means??

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    "y" is a string literal and considered a pointer for purposes of the comparison in that bit of code. You can't test for equality in the manner you are trying to do it. If you are testing C-style strings (characters array) you need to use the strcmp function. If you are using C++ string containers then you can do it as you have it. If you are just testing for a single character, you can do this:

    Code:
    char attack;
    ...
    if( attack == 'y' )
    Make sure your attack variable is an appropriate type to be comparing in the test.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    thanks hk_,mp!! it works great!! one more question, when the player takes the hit, is there any way of displaying it on the screen, here is my example:

    int PlayerH = 10; // declare varible

    // you get hit so

    PlayerH=PlayerH-5;

    how do i display on the screen that there is only 5 helf points left??

    any help would be greatly appriciated

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    cout<<"You have "<<PlayerH<<" points left.";

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. compiling my code, i can't fix error
    By howru in forum C Programming
    Replies: 2
    Last Post: 04-22-2008, 03:38 AM
  3. sort of stuck
    By bobbie18 in forum C Programming
    Replies: 5
    Last Post: 04-04-2008, 04:38 PM
  4. C++ code need help to fix
    By McReal in forum C++ Programming
    Replies: 9
    Last Post: 05-12-2007, 02:48 PM
  5. Replies: 6
    Last Post: 10-23-2006, 07:22 PM